diff --git a/jstests/update7.js b/jstests/update7.js new file mode 100644 index 00000000000..7cfc2a3b268 --- /dev/null +++ b/jstests/update7.js @@ -0,0 +1,28 @@ + +t = db.update7; +t.drop(); + +function s(){ + return t.find().sort( { _id : 1 } ).map( function(z){ return z.x; } ); +} + +t.save( { _id : 1 , x : 1 } ); +t.save( { _id : 2 , x : 5 } ); + +assert.eq( "1,5" , s() , "A" ); + +t.update( {} , { $inc : { x : 1 } } ); +assert.eq( "2,5" , s() , "B" ); + +t.update( { _id : 1 } , { $inc : { x : 1 } } ); +assert.eq( "3,5" , s() , "C" ); + +t.update( { _id : 2 } , { $inc : { x : 1 } } ); +assert.eq( "3,6" , s() , "D" ); + +t.update( {} , { $inc : { x : 1 } } , false , true ); +assert.eq( "4,7" , s() , "E" ); + +t.update( {} , { $set : { x : 2 } } , false , true ); +assert.eq( "2,2" , s() , "E" ); + diff --git a/scripting/sm_db.cpp b/scripting/sm_db.cpp index 526fe2160d2..b6af6bd1413 100644 --- a/scripting/sm_db.cpp +++ b/scripting/sm_db.cpp @@ -225,9 +225,10 @@ namespace mongo { string ns = c.toString( argv[0] ); bool upsert = argc > 3 && c.toBoolean( argv[3] ); + bool multi = argc > 4 && c.toBoolean( argv[4] ); try { - conn->update( ns , c.toObject( argv[1] ) , c.toObject( argv[2] ) , upsert ); + conn->update( ns , c.toObject( argv[1] ) , c.toObject( argv[2] ) , upsert , multi ); return JS_TRUE; } catch ( ... ){ diff --git a/shell/collection.js b/shell/collection.js index 3688b6a553d..8ee12f6bb24 100644 --- a/shell/collection.js +++ b/shell/collection.js @@ -147,11 +147,11 @@ DBCollection.prototype.remove = function( t ){ this._mongo.remove( this._fullName , this._massageObject( t ) ); } -DBCollection.prototype.update = function( query , obj , upsert ){ +DBCollection.prototype.update = function( query , obj , upsert , multi ){ assert( query , "need a query" ); assert( obj , "need an object" ); this._validateObject( obj ); - this._mongo.update( this._fullName , query , obj , upsert ? true : false ); + this._mongo.update( this._fullName , query , obj , upsert ? true : false , multi ? true : false ); } DBCollection.prototype.save = function( obj ){