diff options
3 files changed, 21 insertions, 11 deletions
diff --git a/buildscripts/resmokeconfig/suites/retryable_writes_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/retryable_writes_jscore_passthrough.yml index 040049f458a..0d8a244567e 100644 --- a/buildscripts/resmokeconfig/suites/retryable_writes_jscore_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/retryable_writes_jscore_passthrough.yml @@ -32,6 +32,7 @@ selector: # TODO SERVER-31242: findAndModify no-op retry should respect the fields option. - jstests/core/crud_api.js - jstests/core/find_and_modify2.js + - jstests/core/find_and_modify_pipeline_update.js - jstests/core/find_and_modify_server6865.js # TODO SERVER-31245: Inserts to "system.indexes" bypass the check for retryability. diff --git a/jstests/core/find_and_modify_pipeline_update.js b/jstests/core/find_and_modify_pipeline_update.js index 0a674d3cf38..298c5cc1788 100644 --- a/jstests/core/find_and_modify_pipeline_update.js +++ b/jstests/core/find_and_modify_pipeline_update.js @@ -1,5 +1,6 @@ /** * Tests the pipeline-style update is accepted by the findAndModify command. + * @tags: [requires_non_retryable_writes] */ (function() { "use strict"; @@ -7,25 +8,37 @@ 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. + assert.commandWorked(coll.insert([{_id: 0}, {_id: 1}, {_id: 2}, {_id: 3}, {_id: 4}])); 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 pipeline-style update supports the 'fields' argument. + assert(coll.drop()); + assert.commandWorked( + coll.insert([{_id: 0, x: 0}, {_id: 1, x: 1}, {_id: 2, x: 2}, {_id: 3, x: 3}])); + found = coll.findAndModify({query: {_id: 0}, update: [{$addFields: {y: 0}}], fields: {x: 0}}); + assert.eq(found, {_id: 0}); + + found = coll.findAndModify({query: {_id: 1}, update: [{$addFields: {y: 1}}], fields: {x: 1}}); + assert.eq(found, {_id: 1, x: 1}); + + found = coll.findAndModify( + {query: {_id: 2}, update: [{$addFields: {y: 2}}], fields: {x: 0}, new: true}); + assert.eq(found, {_id: 2, y: 2}); + + found = coll.findAndModify( + {query: {_id: 3}, update: [{$addFields: {y: 3}}], fields: {x: 1}, new: true}); + assert.eq(found, {_id: 3, x: 3}); + // 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-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}})); diff --git a/src/mongo/db/query/find_and_modify_request.cpp b/src/mongo/db/query/find_and_modify_request.cpp index 3b0dc3b4957..375ea84d7dc 100644 --- a/src/mongo/db/query/find_and_modify_request.cpp +++ b/src/mongo/db/query/find_and_modify_request.cpp @@ -221,10 +221,6 @@ StatusWith<FindAndModifyRequest> FindAndModifyRequest::parseFromBSON(NamespaceSt if (arrayFiltersSet) { return {ErrorCodes::FailedToParse, "Cannot specify arrayFilters and a pipeline update"}; } - if (!fields.isEmpty()) { - // TODO SERVER-40404 - return {ErrorCodes::NotImplemented, "No support for fields and pipeline update"}; - } if (!sort.isEmpty()) { // TODO SERVER-40405 return {ErrorCodes::NotImplemented, "No support for sort and pipeline update"}; |