diff options
-rw-r--r-- | jstests/remove_justone.js | 16 | ||||
-rw-r--r-- | scripting/sm_db.cpp | 9 | ||||
-rw-r--r-- | shell/collection.js | 4 |
3 files changed, 24 insertions, 5 deletions
diff --git a/jstests/remove_justone.js b/jstests/remove_justone.js new file mode 100644 index 00000000000..e412a13483c --- /dev/null +++ b/jstests/remove_justone.js @@ -0,0 +1,16 @@ + +t = db.remove_justone +t.drop() + +t.insert( { x : 1 } ) +t.insert( { x : 1 } ) +t.insert( { x : 1 } ) +t.insert( { x : 1 } ) + +assert.eq( 4 , t.count() ) + +t.remove( { x : 1 } , true ) +assert.eq( 3 , t.count() ) + +t.remove( { x : 1 } ) +assert.eq( 0 , t.count() ) diff --git a/scripting/sm_db.cpp b/scripting/sm_db.cpp index 4a359eb0510..b747d4fc13e 100644 --- a/scripting/sm_db.cpp +++ b/scripting/sm_db.cpp @@ -326,7 +326,7 @@ namespace mongo { } JSBool mongo_remove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){ - smuassert( cx , "mongo_remove needs 2 arguments" , argc == 2 ); + smuassert( cx , "mongo_remove needs 2 or 3 arguments" , argc == 2 || argc == 3 ); smuassert( cx , "2nd param to insert has to be an object" , JSVAL_IS_OBJECT( argv[1] ) ); Convertor c( cx ); @@ -340,9 +340,12 @@ namespace mongo { string ns = c.toString( argv[0] ); BSONObj o = c.toObject( argv[1] ); - + bool justOne = false; + if ( argc > 2 ) + justOne = c.toBoolean( argv[2] ); + try { - conn->remove( ns , o ); + conn->remove( ns , o , justOne ); return JS_TRUE; } catch ( ... ){ diff --git a/shell/collection.js b/shell/collection.js index b7f595a4e94..7a7676f27c1 100644 --- a/shell/collection.js +++ b/shell/collection.js @@ -170,8 +170,8 @@ DBCollection.prototype.insert = function( obj , _allow_dot ){ this._lastID = obj._id; } -DBCollection.prototype.remove = function( t ){ - this._mongo.remove( this._fullName , this._massageObject( t ) ); +DBCollection.prototype.remove = function( t , justOne ){ + this._mongo.remove( this._fullName , this._massageObject( t ) , justOne ? true : false ); } DBCollection.prototype.update = function( query , obj , upsert , multi ){ |