0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

$where fix

This commit is contained in:
Eliot Horowitz 2009-01-29 15:58:54 -05:00
parent bf904dc9ec
commit 4a01d610ad
3 changed files with 10 additions and 4 deletions

View File

@ -1,5 +1,4 @@
db = connect("test");
t = db.getCollection( "where1" );
t.drop();
@ -7,4 +6,8 @@ t.save( { a : 1 } );
t.save( { a : 2 } );
t.save( { a : 3 } );
assert.eq( 1 , t.find( function(){ return this.a == 2; } ).length() );
assert.eq( 1 , t.find( function(){ return this.a == 2; } ).length() , "A" );
assert.eq( 1 , t.find( { $where : "this.a == 2" } ).toArray().length , "B" );
assert.eq( 1 , t.find( "this.a == 2" ).toArray().length , "C" );

View File

@ -167,7 +167,10 @@ Local<v8::Object> mongoToV8( BSONObj & m , bool array ){
void v8ToMongoElement( BSONObjBuilder & b , v8::Handle<v8::String> name , const string sname , v8::Handle<v8::Value> value ){
if ( value->IsString() ){
b.append( sname.c_str() , toSTLString( value ).c_str() );
if ( sname == "$where" )
b.appendCode( sname.c_str() , toSTLString( value ).c_str() );
else
b.append( sname.c_str() , toSTLString( value ).c_str() );
return;
}

View File

@ -71,7 +71,7 @@ DBCollection.prototype._massageObject = function( q ){
if ( q.length == 24 )
return { _id : q };
throw "don't know how to handle string [" + q + "]";
return { $where : q };
}
throw "don't know how to massage : " + type;