예제 #1
0
파일: db.cpp 프로젝트: opinionaided/mongo
 const char *ourgetns() {
     Client *c = currentClient.get();
     if ( ! c )
         return "";
     Client::Context* cc = c->getContext();
     return cc ? cc->ns() : "";
 }
예제 #2
0
    StatusWithMatchExpression expressionParserWhereCallbackReal(const BSONElement& where) {
        if ( !haveClient() )
            return StatusWithMatchExpression( ErrorCodes::BadValue, "no current client needed for $where" );

        Client::Context* context = cc().getContext();
        if ( !context )
            return StatusWithMatchExpression( ErrorCodes::BadValue, "no context in $where parsing" );

        const char* ns = context->ns();
        if ( !ns )
            return StatusWithMatchExpression( ErrorCodes::BadValue, "no ns in $where parsing" );

        if ( !globalScriptEngine )
            return StatusWithMatchExpression( ErrorCodes::BadValue, "no globalScriptEngine in $where parsing" );

        auto_ptr<WhereMatchExpression> exp( new WhereMatchExpression() );
        if ( where.type() == String || where.type() == Code ) {
            Status s = exp->init( ns, where.valuestr(), BSONObj() );
            if ( !s.isOK() )
                return StatusWithMatchExpression( s );
            return StatusWithMatchExpression( exp.release() );
        }

        if ( where.type() == CodeWScope ) {
            Status s = exp->init( ns,
                                  where.codeWScopeCode(),
                                  BSONObj( where.codeWScopeScopeDataUnsafe() ) );
            if ( !s.isOK() )
                return StatusWithMatchExpression( s );
            return StatusWithMatchExpression( exp.release() );
        }

        return StatusWithMatchExpression( ErrorCodes::BadValue, "$where got bad type" );
    }
예제 #3
0
파일: pdfile.cpp 프로젝트: ChrisKozak/mongo
 string getDbContext() {
     stringstream ss;
     Client * c = currentClient.get();
     if ( c ) {
         Client::Context * cx = c->getContext();
         if ( cx ) {
             Database *database = cx->db();
             if ( database ) {
                 ss << database->name() << ' ';
                 ss << cx->ns() << ' ';
             }
         }
     }
     return ss.str();
 }