summaryrefslogtreecommitdiff
path: root/jstests/core/find_and_modify_pipeline_update.js
diff options
context:
space:
mode:
authorCharlie Swanson <charlie.swanson@mongodb.com>2019-04-17 09:55:42 -0400
committerCharlie Swanson <charlie.swanson@mongodb.com>2019-04-30 21:28:47 -0400
commit7e4fe022c0d1542519f613d5e718a11e958a31c1 (patch)
tree9c56b43e5589918cb183c12e0b2e742e9b84818b /jstests/core/find_and_modify_pipeline_update.js
parent55790d8e6b46a8d337dbc069d04fa12fda5e9583 (diff)
downloadmongo-7e4fe022c0d1542519f613d5e718a11e958a31c1.tar.gz
SERVER-40397 Add pipeline updates to findAndModify
Adds the ability to specify an array representing an aggregation pipeline to the 'udpate' argument of findAndModify. Certain options like 'sort' and 'fields' are not yet supported.
Diffstat (limited to 'jstests/core/find_and_modify_pipeline_update.js')
-rw-r--r--jstests/core/find_and_modify_pipeline_update.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/jstests/core/find_and_modify_pipeline_update.js b/jstests/core/find_and_modify_pipeline_update.js
new file mode 100644
index 00000000000..ffb8641bb91
--- /dev/null
+++ b/jstests/core/find_and_modify_pipeline_update.js
@@ -0,0 +1,52 @@
+/**
+ * Tests the pipeline-style update is accepted by the findAndModify command.
+ *
+ * TODO SERVER-40402: Remove 'assumes_write_concern_unchanged' tag.
+ * @tags: [assumes_write_concern_unchanged]
+ */
+(function() {
+ "use strict";
+
+ const coll = db.find_and_modify_pipeline_update;
+ coll.drop();
+
+ assert.commandWorked(coll.insert([{_id: 0}, {_id: 1}, {_id: 2}, {_id: 3}, {_id: 4}]));
+
+ // Test that it generally works.
+ let found = coll.findAndModify({query: {_id: 0}, update: [{$addFields: {y: 1}}]});
+ assert.eq(found, {_id: 0});
+ found = coll.findAndModify({query: {_id: 0}, update: [{$addFields: {z: 2}}], new: true});
+ assert.eq(found, {_id: 0, y: 1, z: 2});
+
+ // Test that it rejects the combination of arrayFilters and a pipeline-style update.
+ let err = assert.throws(
+ () => coll.findAndModify(
+ {query: {_id: 1}, update: [{$addFields: {y: 1}}], arrayFilters: [{"i.x": 4}]}));
+ assert.eq(err.code, ErrorCodes.FailedToParse);
+ // SERVER-40399 Add support for collation
+ err = assert.throws(
+ () => coll.findAndModify(
+ {query: {_id: 1}, update: [{$addFields: {y: 1}}], collation: {locale: "en_US"}}));
+ assert.eq(err.code, ErrorCodes.NotImplemented);
+
+ // SERVER-40404 Add support for fields.
+ err = assert.throws(() => coll.findAndModify(
+ {query: {_id: 1}, update: [{$addFields: {y: 1}}], fields: {_id: 0}}));
+ assert.eq(err.code, ErrorCodes.NotImplemented);
+
+ // SERVER-40405 Add support for sort.
+ err = assert.throws(() => coll.findAndModify(
+ {query: {_id: 1}, update: [{$addFields: {y: 1}}], sort: {_id: -1}}));
+ assert.eq(err.code, ErrorCodes.NotImplemented);
+
+ // SERVER-40403 Add support for writeConcern.
+ err =
+ assert.throws(() => coll.findAndModify(
+ {query: {_id: 1}, update: [{$addFields: {y: 1}}], writeConcern: {w: 1}}));
+
+ // SERVER-40401 Add support for bypassDocumentValidation.
+ err = assert.throws(
+ () => coll.findAndModify(
+ {query: {_id: 1}, update: [{$addFields: {y: 1}}], bypassDocumentValidation: true}));
+ assert.eq(err.code, ErrorCodes.NotImplemented);
+}());