Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix search on $ref , $id SERVER-223

  • Loading branch information...
commit d4961e1575f4a4229863eaf71b810cd0d9daf9c5 1 parent 7cadc27
@erh erh authored
Showing with 24 additions and 3 deletions.
  1. +6 −1 db/matcher.cpp
  2. +14 −0 jstests/ref2.js
  3. +4 −2 shell/collection.js
View
7 db/matcher.cpp
@@ -233,6 +233,11 @@ namespace mongo {
addBasic(b->done().firstElement(), BSONObj::NE);
ok = true;
}
+ else if ( fn[1] == 'r' && fn[3] == 'f' && fn[4] == 0 ){
+ // { $ref : xxx } - treat as normal object
+ ok = false;
+ break;
+ }
else
uassert("invalid $operator", false);
}
@@ -261,7 +266,7 @@ namespace mongo {
ok = true;
}
else
- uassert("invalid $operator", false);
+ uassert( (string)"invalid $operator: " + fn , false);
}
else {
ok = false;
View
14 jstests/ref2.js
@@ -0,0 +1,14 @@
+
+t = db.ref2;
+t.drop();
+
+a = { $ref : "foo" , $id : 1 };
+b = { $ref : "foo" , $id : 2 };
+
+
+t.save( { name : "a" , r : a } );
+t.save( { name : "b" , r : b } );
+
+assert.eq( 2 , t.find().count() , "A" );
+assert.eq( 1 , t.find( { r : a } ).count() , "B" );
+assert.eq( 1 , t.find( { r : b } ).count() , "C" );
View
6 shell/collection.js
@@ -92,6 +92,8 @@ DBCollection.prototype._validateObject = function( o ){
throw "can't save a DBQuery object";
}
+DBCollection._allowedFields = { $id : 1 , $ref : 1 };
+
DBCollection.prototype._validateForStorage = function( o ){
this._validateObject( o );
for ( var k in o ){
@@ -99,8 +101,8 @@ DBCollection.prototype._validateForStorage = function( o ){
throw "can't have . in field names [" + k + "]" ;
}
- if ( k.indexOf( "$" ) == 0 ) {
- throw "field names cannot start with $ [" + k + "]" ;
+ if ( k.indexOf( "$" ) == 0 && ! DBCollection._allowedFields[k] ) {
+ throw "field names cannot start with $ [" + k + "]";
}
if ( o[k] !== null && typeof( o[k] ) === "object" ) {
Please sign in to comment.
Something went wrong with that request. Please try again.