diff options
-rw-r--r-- | db/matcher.cpp | 2 | ||||
-rw-r--r-- | jstests/remove_undefined.js | 28 | ||||
-rw-r--r-- | shell/collection.js | 5 | ||||
-rw-r--r-- | shell/mongo_vstudio.cpp | 9 |
4 files changed, 44 insertions, 0 deletions
diff --git a/db/matcher.cpp b/db/matcher.cpp index 494063f4bed..38e8e056b25 100644 --- a/db/matcher.cpp +++ b/db/matcher.cpp @@ -306,6 +306,8 @@ namespace mongo { BSONObjIterator i(jsobj); while ( i.more() ) { BSONElement e = i.next(); + + uassert( 13629 , "can't have undefined in a query expression" , e.type() != Undefined ); if ( parseOrNor( e, subMatcher ) ) { continue; diff --git a/jstests/remove_undefined.js b/jstests/remove_undefined.js new file mode 100644 index 00000000000..d5344a3a562 --- /dev/null +++ b/jstests/remove_undefined.js @@ -0,0 +1,28 @@ + +t = db.drop_undefined.js + +t.insert( { _id : 1 } ) +t.insert( { _id : 2 } ) +t.insert( { _id : null } ) + +z = { foo : 1 , x : null } + +t.remove( { x : z.bar } ) +assert.eq( 3 , t.count() , "A1" ) + +t.remove( { x : undefined } ) +assert.eq( 3 , t.count() , "A2" ) + +assert.throws( function(){ t.remove( { _id : z.bar } ) } , null , "B1" ) +assert.throws( function(){ t.remove( { _id : undefined } ) } , null , "B2" ) + + +t.remove( { _id : z.x } ) +assert.eq( 2 , t.count() , "C1" ) + +t.insert( { _id : null } ) +assert.eq( 3 , t.count() , "C2" ) + +assert.throws( function(){ t.remove( { _id : undefined } ) } , null, "C3" ) +assert.eq( 3 , t.count() , "C4" ) + diff --git a/shell/collection.js b/shell/collection.js index 39cd04a0936..b901f4b56d2 100644 --- a/shell/collection.js +++ b/shell/collection.js @@ -174,6 +174,11 @@ DBCollection.prototype.insert = function( obj , _allow_dot ){ } DBCollection.prototype.remove = function( t , justOne ){ + for ( var k in t ){ + if ( k == "_id" && typeof( t[k] ) == "undefined" ){ + throw "can't have _id set to undefined in a remove expression" + } + } this._mongo.remove( this._fullName , this._massageObject( t ) , justOne ? true : false ); } diff --git a/shell/mongo_vstudio.cpp b/shell/mongo_vstudio.cpp index 9b6c9b6993c..d065f9d1697 100644 --- a/shell/mongo_vstudio.cpp +++ b/shell/mongo_vstudio.cpp @@ -127,6 +127,10 @@ const StringData _jscode_raw_utils = "\n" "assert.throws = function( func , params , msg ){\n" "if ( assert._debug && msg ) print( \"in assert for: \" + msg );\n" +"\n" +"if ( params && typeof( params ) == \"string\" )\n" +"throw \"2nd argument to assert.throws has to be an array\"\n" +"\n" "try {\n" "func.apply( null , params );\n" "}\n" @@ -2940,6 +2944,11 @@ const StringData _jscode_raw_collection = "}\n" "\n" "DBCollection.prototype.remove = function( t , justOne ){\n" +"for ( var k in t ){\n" +"if ( k == \"_id\" && typeof( t[k] ) == \"undefined\" ){\n" +"throw \"can't have _id set to undefined in a remove expression\"\n" +"}\n" +"}\n" "this._mongo.remove( this._fullName , this._massageObject( t ) , justOne ? true : false );\n" "}\n" "\n" |