diff options
author | Tess Avitabile <tess.avitabile@mongodb.com> | 2017-04-04 13:14:40 -0400 |
---|---|---|
committer | Tess Avitabile <tess.avitabile@mongodb.com> | 2017-04-04 13:15:20 -0400 |
commit | 6b4a0c3395a541543b8fd5abd9c853fd04b8e80f (patch) | |
tree | 395df173c6620f7fb9578256441fa3d32a9384a5 /src/mongo/shell/crud_api.js | |
parent | 83bc8601476096bdb666f825c3d516cb7af4cb35 (diff) | |
download | mongo-6b4a0c3395a541543b8fd5abd9c853fd04b8e80f.tar.gz |
SERVER-28576 Add arrayFilters parameter to update and findAndModify shell helpers
Diffstat (limited to 'src/mongo/shell/crud_api.js')
-rw-r--r-- | src/mongo/shell/crud_api.js | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/mongo/shell/crud_api.js b/src/mongo/shell/crud_api.js index 99904fcb3ea..32ad1240b44 100644 --- a/src/mongo/shell/crud_api.js +++ b/src/mongo/shell/crud_api.js @@ -51,9 +51,11 @@ DBCollection.prototype.addIdIfNeeded = function(obj) { * * { insertOne: { document: { a: 1 } } } * -* { updateOne: { filter: {a:2}, update: {$set: {a:2}}, upsert:true, collation: {locale: "fr"} } } +* { updateOne: { filter: {a:2}, update: {$set: {"a.$[i]":2}}, upsert:true, collation: {locale: +* "fr"}, arrayFilters: [{i: 0}] } } * -* { updateMany: { filter: {a:2}, update: {$set: {a:2}}, upsert:true collation: {locale: "fr"} } } +* { updateMany: { filter: {a:2}, update: {$set: {"a.$[i]":2}}, upsert:true collation: {locale: +* "fr"}, arrayFilters: [{i: 0}] } } * * { deleteOne: { filter: {c:1}, collation: {locale: "fr"} } } * @@ -117,6 +119,10 @@ DBCollection.prototype.bulkWrite = function(operations, options) { operation.collation(op.updateOne.collation); } + if (op.updateOne.arrayFilters) { + operation.arrayFilters(op.updateOne.arrayFilters); + } + operation.updateOne(op.updateOne.update); } else if (op.updateMany) { if (!op.updateMany.filter) { @@ -137,6 +143,10 @@ DBCollection.prototype.bulkWrite = function(operations, options) { operation.collation(op.updateMany.collation); } + if (op.updateMany.arrayFilters) { + operation.arrayFilters(op.updateMany.arrayFilters); + } + operation.update(op.updateMany.update); } else if (op.replaceOne) { if (!op.replaceOne.filter) { @@ -551,6 +561,10 @@ DBCollection.prototype.updateOne = function(filter, update, options) { op.collation(opts.collation); } + if (opts.arrayFilters) { + op.arrayFilters(opts.arrayFilters); + } + op.updateOne(update); try { @@ -630,6 +644,10 @@ DBCollection.prototype.updateMany = function(filter, update, options) { op.collation(opts.collation); } + if (opts.arrayFilters) { + op.arrayFilters(opts.arrayFilters); + } + op.update(update); try { @@ -819,6 +837,10 @@ DBCollection.prototype.findOneAndUpdate = function(filter, update, options) { cmd.collation = opts.collation; } + if (opts.arrayFilters) { + cmd.arrayFilters = opts.arrayFilters; + } + // Set flags cmd.upsert = (typeof opts.upsert == 'boolean') ? opts.upsert : false; cmd.new = (typeof opts.returnNewDocument == 'boolean') ? opts.returnNewDocument : false; |