diff options
Diffstat (limited to 'src/mongo/db/update/pipeline_executor_test.cpp')
| -rw-r--r-- | src/mongo/db/update/pipeline_executor_test.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/mongo/db/update/pipeline_executor_test.cpp b/src/mongo/db/update/pipeline_executor_test.cpp index c650e06749d..d237dd4f78e 100644 --- a/src/mongo/db/update/pipeline_executor_test.cpp +++ b/src/mongo/db/update/pipeline_executor_test.cpp @@ -719,5 +719,45 @@ TEST_F(PipelineExecutorV2ModeTest, TestIndexesAffectedWithArraysAfterIndexPath) } } +/** + * Verifies the fix for SERVER-76934 in the case where the original document has a duplicate field. + */ +TEST_F(PipelineExecutorV2ModeTest, TestIndexesAffectedWithArraysAfterIndexPath1) { + boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + BSONObj preImage( + fromjson("{f1: {paddingField: 'largeValueString'}, k: {c: 1, c: 2, paddingField: " + "'largeValueString'}}")); + + auto doc = mutablebson::Document(preImage); + const std::vector<BSONObj> pipeline{ + fromjson("{$replaceWith: {$literal: {f1: {paddingField: 'largeValueString'}, k: {c: 4, " + "paddingField: 'largeValueString'}} }}")}; + PipelineExecutor exec(expCtx, pipeline); + ASSERT_THROWS_CODE_AND_WHAT(exec.applyUpdate(getApplyParams(doc.root())), + AssertionException, + 7693400, + "Document already has a field named 'c'"); +} + +/** + * Verifies the fix for SERVER-76934 in the case where the pipeline tries to add a duplicate field. + */ +TEST_F(PipelineExecutorV2ModeTest, TestIndexesAffectedWithArraysAfterIndexPath2) { + boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + BSONObj preImage( + fromjson("{f1: {paddingField: 'largeValueString'}, k: {c: 1, paddingField: " + "'largeValueString'}}")); + + auto doc = mutablebson::Document(preImage); + const std::vector<BSONObj> pipeline{ + fromjson("{$replaceWith: {$literal: {f1: {paddingField: 'largeValueString'}, k: {c: 4, c: " + "5, paddingField: 'largeValueString'}} }}")}; + PipelineExecutor exec(expCtx, pipeline); + ASSERT_THROWS_CODE_AND_WHAT(exec.applyUpdate(getApplyParams(doc.root())), + AssertionException, + 7693400, + "Document already has a field named 'c'"); +} + } // namespace } // namespace mongo |
