Exemple #1
0
 const char *ourgetns() {
     Client *c = currentClient.get();
     if ( ! c )
         return "";
     Client::Context* cc = c->getContext();
     return cc ? cc->ns() : "";
 }
Exemple #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" );
    }
Exemple #3
0
 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();
 }