Skip to content
Browse files

Spider Monkey: find field spec

  • Loading branch information...
1 parent a83e3bb commit 0422e9a22489718b8be1e0e1d07e805018151df9 @erh erh committed May 9, 2009
Showing with 25 additions and 2 deletions.
  1. +23 −0 jstests/eval5.js
  2. +2 −2 scripting/sm_db.cpp
View
23 jstests/eval5.js
@@ -0,0 +1,23 @@
+
+t = db.eval5;
+t.drop();
+
+t.save( { a : 1 , b : 2 , c : 3 } );
+
+assert.eq( 3 ,
+ db.eval(
+ function(z){
+ return db.eval5.find().toArray()[0].c;
+ }
+ ) ,
+ "something weird A"
+ );
+
+assert.isnull(
+ db.eval(
+ function(z){
+ return db.eval5.find( {} , { a : 1 } ).toArray()[0].c;
+ }
+ ),
+ "field spec didn't work"
+ );
View
4 scripting/sm_db.cpp
@@ -125,15 +125,15 @@ namespace mongo {
string ns = c.toString( argv[0] );
BSONObj q = c.toObject( argv[1] );
- //uassert( "field selector not supported yet in mongo_find" , argv[2] == JSVAL_NULL );
+ BSONObj f = c.toObject( argv[2] );
int nToReturn = c.toNumber( argv[3] );
int nToSkip = c.toNumber( argv[4] );
bool slaveOk = c.getBoolean( obj , "slaveOk" );
try {
- auto_ptr<DBClientCursor> cursor = conn->query( ns , q , nToReturn , nToSkip , 0 , slaveOk ? Option_SlaveOk : 0 );
+ auto_ptr<DBClientCursor> cursor = conn->query( ns , q , nToReturn , nToSkip , f.nFields() ? &f : 0 , slaveOk ? Option_SlaveOk : 0 );
JSObject * mycursor = JS_NewObject( cx , &internal_cursor_class , 0 , 0 );
JS_SetPrivate( cx , mycursor , cursor.release() );

0 comments on commit 0422e9a

Please sign in to comment.
Something went wrong with that request. Please try again.