diff options
author | Mathias Stearn <mathias@10gen.com> | 2009-12-30 20:08:43 -0500 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2009-12-30 20:08:43 -0500 |
commit | 225173bb31d7536b9e402145c7f65db00e2523ab (patch) | |
tree | 1127a8429f572ab5f8a3f39b911249bdfce951fc /shell | |
parent | 53667da6d84c5943c1b778f31c20df9a63700bde (diff) | |
download | mongo-225173bb31d7536b9e402145c7f65db00e2523ab.tar.gz |
FindAndModify command SERVER-459
Diffstat (limited to 'shell')
-rw-r--r-- | shell/collection.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/shell/collection.js b/shell/collection.js index f3b5a889a4b..d94bad0514d 100644 --- a/shell/collection.js +++ b/shell/collection.js @@ -42,6 +42,7 @@ DBCollection.prototype.help = function(){ print("\tdb.foo.find(...).skip(n)"); print("\tdb.foo.find(...).sort(...)"); print("\tdb.foo.findOne([query])"); + print("\tdb.foo.findAndModify( { update : ... , remove : bool [, query: {}, sort: {}, 'new': false] } )"); print("\tdb.foo.getDB() get DB object associated with collection"); print("\tdb.foo.getIndexes()"); print("\tdb.foo.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )"); @@ -308,6 +309,22 @@ DBCollection.prototype.drop = function(){ return true; } +DBCollection.prototype.findAndModify = function(args){ + var cmd = { findandmodify: this.getName() }; + for (key in args){ + cmd[key] = args[key]; + } + + var ret = this._db.runCommand( cmd ); + if ( ! ret.ok ){ + if (ret.errmsg == "No matching object found"){ + return {}; + } + throw "findAndModifyFailed failed: " + tojson( ret.errmsg ); + } + return ret.value; +} + DBCollection.prototype.renameCollection = function( newName , dropTarget ){ return this._db._adminCommand( { renameCollection : this._fullName , to : this._db._name + "." + newName , |