diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-10-22 09:43:31 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-10-22 09:43:31 -0400 |
commit | 1bc6fff4e69d93f6f804a6df8d48dbf3469a6148 (patch) | |
tree | cd13997c42de8bb7503fcd2f7072c9128b85c152 | |
parent | e8466f3dc5d2e8c7db7f1749d25d587d0ec0133e (diff) | |
download | mongo-1bc6fff4e69d93f6f804a6df8d48dbf3469a6148.tar.gz |
shell multi-update option and test SERVER-268
-rw-r--r-- | jstests/update7.js | 28 | ||||
-rw-r--r-- | scripting/sm_db.cpp | 3 | ||||
-rw-r--r-- | shell/collection.js | 4 |
3 files changed, 32 insertions, 3 deletions
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 ){ |