summaryrefslogtreecommitdiff
path: root/src/mongo/db/update
diff options
context:
space:
mode:
authorAlya Berciu <alyacarina@gmail.com>2021-05-13 11:25:54 +0100
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-18 14:13:29 +0000
commit1e6e3b3c41cfd2db55a0dd3692c47506cf2a279c (patch)
tree460962e584d1e9700933f7d1d91e1af80be74d49 /src/mongo/db/update
parent5c9288ff2d32ef9b24625883e6f67d279f344356 (diff)
downloadmongo-1e6e3b3c41cfd2db55a0dd3692c47506cf2a279c.tar.gz
SERVER-52307 Enable dots and dollars feature flag
Diffstat (limited to 'src/mongo/db/update')
-rw-r--r--src/mongo/db/update/rename_node_test.cpp3
-rw-r--r--src/mongo/db/update/set_node_test.cpp1
-rw-r--r--src/mongo/db/update/unset_node_test.cpp50
3 files changed, 42 insertions, 12 deletions
diff --git a/src/mongo/db/update/rename_node_test.cpp b/src/mongo/db/update/rename_node_test.cpp
index 1ac12e6254d..d4bf8c85e6b 100644
--- a/src/mongo/db/update/rename_node_test.cpp
+++ b/src/mongo/db/update/rename_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"
@@ -473,6 +474,7 @@ TEST_F(RenameNodeTest, RenameFromNonExistentPathIsNoOp) {
}
TEST_F(RenameNodeTest, ApplyCannotRemoveRequiredPartOfDBRef) {
+ RAIIServerParameterControllerForTest controller("featureFlagDotsAndDollars", false);
auto update = fromjson("{$rename: {'a.$id': 'b'}}");
boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
RenameNode node;
@@ -579,6 +581,7 @@ TEST_F(RenameNodeTest, ApplyCanRemoveImmutablePathIfNoop) {
}
TEST_F(RenameNodeTest, ApplyCannotCreateDollarPrefixedField) {
+ RAIIServerParameterControllerForTest controller("featureFlagDotsAndDollars", false);
auto update = fromjson("{$rename: {a: '$bad'}}");
boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
RenameNode node;
diff --git a/src/mongo/db/update/set_node_test.cpp b/src/mongo/db/update/set_node_test.cpp
index e1b7598e07b..030a85086b9 100644
--- a/src/mongo/db/update/set_node_test.cpp
+++ b/src/mongo/db/update/set_node_test.cpp
@@ -1053,6 +1053,7 @@ TEST_F(SetNodeTest, ApplyCannotCreateDollarPrefixedFieldInsideSetElement) {
}
TEST_F(SetNodeTest, ApplyCannotCreateDollarPrefixedFieldAtStartOfPath) {
+ RAIIServerParameterControllerForTest controller("featureFlagDotsAndDollars", false);
auto update = fromjson("{$set: {'$bad.a': 1}}");
boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
SetNode node;
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) {