diff options
author | James Wahlin <james.wahlin@mongodb.com> | 2019-09-25 14:26:54 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-09-25 14:26:54 +0000 |
commit | e4571c1eb6034c118b69175989db7753eafc3086 (patch) | |
tree | 7b81e9e24889c88878a1d1e22ec66df8cf1ccc1b | |
parent | d6c8abc4c077e2de13311a92781d9908bb45c397 (diff) | |
download | mongo-e4571c1eb6034c118b69175989db7753eafc3086.tar.gz |
SERVER-43039 db.collection.bulkWrite doesn't support hint with replaceOne
(cherry picked from commit b90eb45382cacc033a4258d0d28ce64acd307caa)
-rw-r--r-- | jstests/core/update_hint.js | 14 | ||||
-rw-r--r-- | src/mongo/shell/crud_api.js | 8 |
2 files changed, 22 insertions, 0 deletions
diff --git a/jstests/core/update_hint.js b/jstests/core/update_hint.js index a223da43949..734ac92e5d2 100644 --- a/jstests/core/update_hint.js +++ b/jstests/core/update_hint.js @@ -104,6 +104,10 @@ function shellHelpersTest() { bulk.find({x: 2}).hint({s: 1}).upsert().updateOne({$set: {y: 1}}); res = bulk.execute(); assert.eq(res.nUpserted, 1); + bulk = coll.initializeUnorderedBulkOp(); + bulk.find({x: 2}).hint({s: 1}).upsert().replaceOne({$set: {y: 1}}); + res = bulk.execute(); + assert.eq(res.nUpserted, 1); res = coll.bulkWrite([{ updateOne: { @@ -123,6 +127,16 @@ function shellHelpersTest() { } }]); assert.eq(res.matchedCount, 2); + + res = coll.bulkWrite([{ + replaceOne: { + filter: {x: 2}, + replacement: {x: 2, y: 3}, + hint: {s: 1}, + upsert: true, + } + }]); + assert.eq(res.upsertedCount, 1); } function failedHintTest() { diff --git a/src/mongo/shell/crud_api.js b/src/mongo/shell/crud_api.js index c428f461be8..3b1fa4a8705 100644 --- a/src/mongo/shell/crud_api.js +++ b/src/mongo/shell/crud_api.js @@ -175,6 +175,10 @@ DBCollection.prototype.bulkWrite = function(operations, options) { operation.collation(op.replaceOne.collation); } + if (op.replaceOne.hint) { + operation.hint(op.replaceOne.hint); + } + operation.replaceOne(op.replaceOne.replacement); } else if (op.deleteOne) { if (!op.deleteOne.filter) { @@ -495,6 +499,10 @@ DBCollection.prototype.replaceOne = function(filter, replacement, options) { op.collation(opts.collation); } + if (opts.hint) { + op.hint(opts.hint); + } + op.replaceOne(replacement); try { |