diff options
author | Xin Hao Zhang <xinhao.zhang@mongodb.com> | 2019-06-13 16:48:24 -0400 |
---|---|---|
committer | Xin Hao Zhang <xinhao.zhang@mongodb.com> | 2019-07-03 10:45:25 -0400 |
commit | 0984d2f5318d54cb6b7691dee1a54fcd953c7357 (patch) | |
tree | b84fc69641dcb167a1650a2d8ac462213496007e /src/mongo/shell/collection.js | |
parent | 6792520dc6a2a0c430c11fc264faa1e061903fbd (diff) | |
download | mongo-0984d2f5318d54cb6b7691dee1a54fcd953c7357.tar.gz |
SERVER-1599 Add support for index hint to update command
(cherry picked from commit 90da71501d23dc1b5a3d78417079fd62e989e035)
Diffstat (limited to 'src/mongo/shell/collection.js')
-rw-r--r-- | src/mongo/shell/collection.js | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/mongo/shell/collection.js b/src/mongo/shell/collection.js index 40a6cbd7cf5..64f079ef984 100644 --- a/src/mongo/shell/collection.js +++ b/src/mongo/shell/collection.js @@ -123,10 +123,10 @@ DBCollection.prototype.help = function() { ".update( query, <update object or pipeline>[, upsert_bool, multi_bool] ) - instead of two flags, you can pass an object with fields: upsert, multi"); print( "\tdb." + shortName + - ".updateOne( filter, <update object or pipeline>, <optional params> ) - update the first matching document, optional parameters are: upsert, w, wtimeout, j"); + ".updateOne( filter, <update object or pipeline>, <optional params> ) - update the first matching document, optional parameters are: upsert, w, wtimeout, j, hint"); print( "\tdb." + shortName + - ".updateMany( filter, <update object or pipeline>, <optional params> ) - update all matching documents, optional parameters are: upsert, w, wtimeout, j"); + ".updateMany( filter, <update object or pipeline>, <optional params> ) - update all matching documents, optional parameters are: upsert, w, wtimeout, j, hint"); print("\tdb." + shortName + ".validate( <full> ) - SLOW"); print("\tdb." + shortName + ".getShardVersion() - only for use with sharding"); print("\tdb." + shortName + @@ -449,6 +449,8 @@ DBCollection.prototype._parseUpdate = function(query, updateSpec, upsert, multi) var wc = undefined; var collation = undefined; var arrayFilters = undefined; + let hint = undefined; + // can pass options via object for improved readability if (typeof(upsert) === "object") { if (multi) { @@ -462,6 +464,7 @@ DBCollection.prototype._parseUpdate = function(query, updateSpec, upsert, multi) upsert = opts.upsert; collation = opts.collation; arrayFilters = opts.arrayFilters; + hint = opts.hint; } // Normalize 'upsert' and 'multi' to booleans. @@ -475,6 +478,7 @@ DBCollection.prototype._parseUpdate = function(query, updateSpec, upsert, multi) return { "query": query, "updateSpec": updateSpec, + "hint": hint, "upsert": upsert, "multi": multi, "wc": wc, @@ -489,6 +493,7 @@ DBCollection.prototype.update = function(query, updateSpec, upsert, multi) { var parsed = this._parseUpdate(query, updateSpec, upsert, multi); var query = parsed.query; var updateSpec = parsed.updateSpec; + const hint = parsed.hint; var upsert = parsed.upsert; var multi = parsed.multi; var wc = parsed.wc; @@ -503,6 +508,10 @@ DBCollection.prototype.update = function(query, updateSpec, upsert, multi) { var bulk = this.initializeOrderedBulkOp(); var updateOp = bulk.find(query); + if (hint) { + updateOp.hint(hint); + } + if (upsert) { updateOp = updateOp.upsert(); } |