Permalink
Browse files

shell support for justOne for removes SERVER-1653

  • Loading branch information...
1 parent 6b9d67d commit fa8b9a8c734c673c62c447bfb1db8a497f2fa5d8 @erh erh committed Aug 22, 2010
Showing with 24 additions and 5 deletions.
  1. +16 −0 jstests/remove_justone.js
  2. +6 −3 scripting/sm_db.cpp
  3. +2 −2 shell/collection.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() )
View
@@ -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 ( ... ){
View
@@ -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 ){

0 comments on commit fa8b9a8

Please sign in to comment.