Permalink
Browse files

fix search on $ref , $id SERVER-223

  • Loading branch information...
1 parent 7cadc27 commit d4961e1575f4a4229863eaf71b810cd0d9daf9c5 @erh erh committed Aug 10, 2009
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
@@ -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
@@ -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
@@ -92,15 +92,17 @@ 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 ){
if ( k.indexOf( "." ) >= 0 ) {
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" ) {

0 comments on commit d4961e1

Please sign in to comment.