diff options
Diffstat (limited to 'src/mongo/db/update/unset_node_test.cpp')
-rw-r--r-- | src/mongo/db/update/unset_node_test.cpp | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/src/mongo/db/update/unset_node_test.cpp b/src/mongo/db/update/unset_node_test.cpp index d45b2472a90..4595183ef0d 100644 --- a/src/mongo/db/update/unset_node_test.cpp +++ b/src/mongo/db/update/unset_node_test.cpp @@ -36,6 +36,7 @@ #include "mongo/db/json.h" #include "mongo/db/pipeline/expression_context_for_test.h" #include "mongo/db/update/update_node_test_fixture.h" +#include "mongo/idl/server_parameter_test_util.h" #include "mongo/unittest/death_test.h" #include "mongo/unittest/unittest.h" @@ -369,18 +370,43 @@ TEST_F(UnsetNodeTest, ApplyFieldWithDot) { } TEST_F(UnsetNodeTest, ApplyCannotRemoveRequiredPartOfDBRef) { - auto update = fromjson("{$unset: {'a.$id': true}}"); - boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); - UnsetNode node; - ASSERT_OK(node.init(update["$unset"]["a.$id"], expCtx)); - - mutablebson::Document doc(fromjson("{a: {$ref: 'c', $id: 0}}")); - setPathTaken(makeRuntimeUpdatePathForTest("a.$id")); - ASSERT_THROWS_CODE_AND_WHAT( - node.apply(getApplyParams(doc.root()["a"]["$id"]), getUpdateNodeApplyParams()), - AssertionException, - ErrorCodes::InvalidDBRef, - "The DBRef $ref field must be followed by a $id field"); + { + RAIIServerParameterControllerForTest controller("featureFlagDotsAndDollars", false); + auto update = fromjson("{$unset: {'a.$id': true}}"); + boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + UnsetNode node; + ASSERT_OK(node.init(update["$unset"]["a.$id"], expCtx)); + + mutablebson::Document doc(fromjson("{a: {$ref: 'c', $id: 0}}")); + setPathTaken(makeRuntimeUpdatePathForTest("a.$id")); + ASSERT_THROWS_CODE_AND_WHAT( + node.apply(getApplyParams(doc.root()["a"]["$id"]), getUpdateNodeApplyParams()), + AssertionException, + ErrorCodes::InvalidDBRef, + "The DBRef $ref field must be followed by a $id field"); + } + { + RAIIServerParameterControllerForTest controller("featureFlagDotsAndDollars", true); + auto update = fromjson("{$unset: {'a.$id': true}}"); + boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + UnsetNode node; + ASSERT_OK(node.init(update["$unset"]["a.$id"], expCtx)); + + mutablebson::Document doc(fromjson("{a: {$ref: 'c', $id: 0}}")); + setPathTaken(makeRuntimeUpdatePathForTest("a.$id")); + auto result = + node.apply(getApplyParams(doc.root()["a"]["$id"]), getUpdateNodeApplyParams()); + ASSERT_FALSE(result.noop); + ASSERT_FALSE(result.indexesAffected); + auto updated = BSON("a" << BSON("$ref" + << "c")); + ASSERT_EQUALS(updated, doc); + ASSERT_FALSE(doc.isInPlaceModeEnabled()); + + assertOplogEntry(fromjson("{$unset: {'a.$id': true}}"), + fromjson("{$v: 2, diff: {sa: {d: {$id: false}}}}")); + ASSERT_EQUALS(getModifiedPaths(), "{a.$id}"); + } } TEST_F(UnsetNodeTest, ApplyCanRemoveRequiredPartOfDBRefIfValidateForStorageIsFalse) { |