|
36 | 36 | #include "mongo/db/json.h" |
37 | 37 | #include "mongo/db/pipeline/expression_context_for_test.h" |
38 | 38 | #include "mongo/db/update/update_node_test_fixture.h" |
| 39 | +#include "mongo/idl/server_parameter_test_util.h" |
39 | 40 | #include "mongo/unittest/death_test.h" |
40 | 41 | #include "mongo/unittest/unittest.h" |
41 | 42 |
|
@@ -369,18 +370,43 @@ TEST_F(UnsetNodeTest, ApplyFieldWithDot) { |
369 | 370 | } |
370 | 371 |
|
371 | 372 | TEST_F(UnsetNodeTest, ApplyCannotRemoveRequiredPartOfDBRef) { |
372 | | - auto update = fromjson("{$unset: {'a.$id': true}}"); |
373 | | - boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); |
374 | | - UnsetNode node; |
375 | | - ASSERT_OK(node.init(update["$unset"]["a.$id"], expCtx)); |
376 | | - |
377 | | - mutablebson::Document doc(fromjson("{a: {$ref: 'c', $id: 0}}")); |
378 | | - setPathTaken(makeRuntimeUpdatePathForTest("a.$id")); |
379 | | - ASSERT_THROWS_CODE_AND_WHAT( |
380 | | - node.apply(getApplyParams(doc.root()["a"]["$id"]), getUpdateNodeApplyParams()), |
381 | | - AssertionException, |
382 | | - ErrorCodes::InvalidDBRef, |
383 | | - "The DBRef $ref field must be followed by a $id field"); |
| 373 | + { |
| 374 | + RAIIServerParameterControllerForTest controller("featureFlagDotsAndDollars", false); |
| 375 | + auto update = fromjson("{$unset: {'a.$id': true}}"); |
| 376 | + boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); |
| 377 | + UnsetNode node; |
| 378 | + ASSERT_OK(node.init(update["$unset"]["a.$id"], expCtx)); |
| 379 | + |
| 380 | + mutablebson::Document doc(fromjson("{a: {$ref: 'c', $id: 0}}")); |
| 381 | + setPathTaken(makeRuntimeUpdatePathForTest("a.$id")); |
| 382 | + ASSERT_THROWS_CODE_AND_WHAT( |
| 383 | + node.apply(getApplyParams(doc.root()["a"]["$id"]), getUpdateNodeApplyParams()), |
| 384 | + AssertionException, |
| 385 | + ErrorCodes::InvalidDBRef, |
| 386 | + "The DBRef $ref field must be followed by a $id field"); |
| 387 | + } |
| 388 | + { |
| 389 | + RAIIServerParameterControllerForTest controller("featureFlagDotsAndDollars", true); |
| 390 | + auto update = fromjson("{$unset: {'a.$id': true}}"); |
| 391 | + boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); |
| 392 | + UnsetNode node; |
| 393 | + ASSERT_OK(node.init(update["$unset"]["a.$id"], expCtx)); |
| 394 | + |
| 395 | + mutablebson::Document doc(fromjson("{a: {$ref: 'c', $id: 0}}")); |
| 396 | + setPathTaken(makeRuntimeUpdatePathForTest("a.$id")); |
| 397 | + auto result = |
| 398 | + node.apply(getApplyParams(doc.root()["a"]["$id"]), getUpdateNodeApplyParams()); |
| 399 | + ASSERT_FALSE(result.noop); |
| 400 | + ASSERT_FALSE(result.indexesAffected); |
| 401 | + auto updated = BSON("a" << BSON("$ref" |
| 402 | + << "c")); |
| 403 | + ASSERT_EQUALS(updated, doc); |
| 404 | + ASSERT_FALSE(doc.isInPlaceModeEnabled()); |
| 405 | + |
| 406 | + assertOplogEntry(fromjson("{$unset: {'a.$id': true}}"), |
| 407 | + fromjson("{$v: 2, diff: {sa: {d: {$id: false}}}}")); |
| 408 | + ASSERT_EQUALS(getModifiedPaths(), "{a.$id}"); |
| 409 | + } |
384 | 410 | } |
385 | 411 |
|
386 | 412 | TEST_F(UnsetNodeTest, ApplyCanRemoveRequiredPartOfDBRefIfValidateForStorageIsFalse) { |
|
0 commit comments