Permalink
Browse files

only strings for $where

  • Loading branch information...
1 parent a1da020 commit 088f487c2a56c3ab39b499a2a58e63377f9041aa @erh erh committed May 14, 2009
Showing with 10 additions and 3 deletions.
  1. +1 −1 db/matcher.cpp
  2. +6 −0 dbtests/jstests.cpp
  3. +3 −2 jstests/where1.js
View
@@ -143,7 +143,7 @@ namespace mongo {
if ( e.eoo() )
break;
- if ( ( e.type() == CodeWScope || e.type() == Code ) && strcmp(e.fieldName(), "$where")==0 ) {
+ if ( ( e.type() == CodeWScope || e.type() == Code || e.type() == String ) && strcmp(e.fieldName(), "$where")==0 ) {
// $where: function()...
uassert( "$where occurs twice?", where == 0 );
where = new Where();
View
@@ -118,6 +118,12 @@ namespace JSTests {
s->setThis( & o );
s->invoke( "return this.z;" , BSONObj() );
ASSERT_EQUALS( "sara" , s->getString( "return" ) );
+
+ s->invoke( "this.z == 'sara';" , BSONObj() );
+ ASSERT_EQUALS( true , s->getBoolean( "return" ) );
+
+ s->invoke( "this.z == 'asara';" , BSONObj() );
+ ASSERT_EQUALS( false , s->getBoolean( "return" ) );
s->invoke( "return this.x == 17;" , BSONObj() );
ASSERT_EQUALS( true , s->getBoolean( "return" ) );
View
@@ -8,6 +8,7 @@ t.save( { a : 3 } );
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( { $where : "return this.a == 2" } ).toArray().length , "B" );
+assert.eq( 1 , t.find( { $where : "this.a == 2" } ).toArray().length , "C" );
-assert.eq( 1 , t.find( "this.a == 2" ).toArray().length , "C" );
+assert.eq( 1 , t.find( "this.a == 2" ).toArray().length , "D" );

0 comments on commit 088f487

Please sign in to comment.