summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Tuckman <ted.tuckman@mongodb.com>2020-07-10 10:19:26 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-10-02 14:00:45 +0000
commit0348620630f3dd86214676e7e9566a6aa6e6be5c (patch)
treea1b84365ffc80bb73c2df02c18029d6f147e147b
parent45637f4d481c8badd6d5a2d95dcb8ae947c78c92 (diff)
downloadmongo-0348620630f3dd86214676e7e9566a6aa6e6be5c.tar.gz
SERVER-25893 Make it easier to construct a Value from a Vector
-rw-r--r--src/mongo/db/exec/add_fields_projection_executor_test.cpp29
-rw-r--r--src/mongo/db/exec/document_value/document_comparator_test.cpp6
-rw-r--r--src/mongo/db/exec/document_value/value.h21
-rw-r--r--src/mongo/db/exec/exclusion_projection_executor_test.cpp78
-rw-r--r--src/mongo/db/exec/inclusion_projection_executor_test.cpp198
-rw-r--r--src/mongo/db/index/sort_key_generator_test.cpp53
-rw-r--r--src/mongo/db/pipeline/aggregation_request_test.cpp17
-rw-r--r--src/mongo/db/pipeline/document_path_support_test.cpp44
-rw-r--r--src/mongo/db/pipeline/document_source_change_stream_test.cpp10
-rw-r--r--src/mongo/db/pipeline/document_source_graph_lookup_test.cpp3
-rw-r--r--src/mongo/db/pipeline/document_source_lookup.cpp8
-rw-r--r--src/mongo/db/pipeline/document_source_lookup_test.cpp10
-rw-r--r--src/mongo/db/pipeline/expression_test.cpp16
13 files changed, 229 insertions, 264 deletions
diff --git a/src/mongo/db/exec/add_fields_projection_executor_test.cpp b/src/mongo/db/exec/add_fields_projection_executor_test.cpp
index 047bbbbc42e..34c280edb29 100644
--- a/src/mongo/db/exec/add_fields_projection_executor_test.cpp
+++ b/src/mongo/db/exec/add_fields_projection_executor_test.cpp
@@ -450,23 +450,22 @@ TEST(AddFieldsProjectionExecutorExecutionTest, AppliesDottedAdditionToEachElemen
AddFieldsProjectionExecutor addition(expCtx);
addition.parse(BSON("a.b" << true));
- vector<Value> nestedValues = {Value(1),
- Value(Document{}),
- Value(Document{{"b", 1}}),
- Value(Document{{"b", 1}, {"c", 2}}),
- Value(vector<Value>{}),
- Value(vector<Value>{Value(1), Value(Document{{"c", 1}})})};
+ auto result = addition.applyProjection(Document{{"a",
+ {1,
+ Document{},
+ Document{{"b", 1}},
+ Document{{"b", 1}, {"c", 2}},
+ vector<Value>{},
+ {1, Document{{"c", 1}}}}}});
// Adds the field "b" to every object in the array. Recurses on non-empty nested arrays.
- vector<Value> expectedNestedValues = {
- Value(Document{{"b", true}}),
- Value(Document{{"b", true}}),
- Value(Document{{"b", true}}),
- Value(Document{{"b", true}, {"c", 2}}),
- Value(vector<Value>{}),
- Value(vector<Value>{Value(Document{{"b", true}}), Value(Document{{"c", 1}, {"b", true}})})};
- auto result = addition.applyProjection(Document{{"a", nestedValues}});
- auto expectedResult = Document{{"a", expectedNestedValues}};
+ auto expectedResult = Document{{"a",
+ {Document{{"b", true}},
+ Document{{"b", true}},
+ Document{{"b", true}},
+ Document{{"b", true}, {"c", 2}},
+ vector<Value>{},
+ {Document{{"b", true}}, Document{{"c", 1}, {"b", true}}}}}};
ASSERT_DOCUMENT_EQ(result, expectedResult);
}
diff --git a/src/mongo/db/exec/document_value/document_comparator_test.cpp b/src/mongo/db/exec/document_value/document_comparator_test.cpp
index 548cd875fd9..c3145f7bbcc 100644
--- a/src/mongo/db/exec/document_value/document_comparator_test.cpp
+++ b/src/mongo/db/exec/document_value/document_comparator_test.cpp
@@ -213,9 +213,9 @@ TEST(DocumentComparatorTest, NestedObjectEqualityRespectsCollator) {
TEST(DocumentComparatorTest, NestedArrayEqualityRespectsCollator) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- const Document doc1{{"foo", std::vector<Value>{Value("a"_sd), Value("b"_sd)}}};
- const Document doc2{{"foo", std::vector<Value>{Value("c"_sd), Value("d"_sd)}}};
- const Document doc3{{"foo", std::vector<Value>{Value("c"_sd), Value("d"_sd), Value("e"_sd)}}};
+ const Document doc1{{"foo", {"a"_sd, "b"_sd}}};
+ const Document doc2{{"foo", {"c"_sd, "d"_sd}}};
+ const Document doc3{{"foo", {"c"_sd, "d"_sd, "e"_sd}}};
ASSERT_TRUE(DocumentComparator(&collator).evaluate(doc1 == doc2));
ASSERT_TRUE(DocumentComparator(&collator).evaluate(doc2 == doc1));
ASSERT_FALSE(DocumentComparator(&collator).evaluate(doc1 == doc3));
diff --git a/src/mongo/db/exec/document_value/value.h b/src/mongo/db/exec/document_value/value.h
index 818c7dc3323..7b593780cbf 100644
--- a/src/mongo/db/exec/document_value/value.h
+++ b/src/mongo/db/exec/document_value/value.h
@@ -385,6 +385,16 @@ public:
template <typename T>
ImplicitValue(T arg) : Value(std::move(arg)) {}
+ ImplicitValue(std::initializer_list<ImplicitValue> values) : Value(convertToValues(values)) {}
+
+ ImplicitValue(std::vector<int> values) : Value(convertToValues(values)) {}
+
+ static std::vector<Value> convertToValues(const std::vector<int>& vec) {
+ std::vector<Value> values;
+ for_each(vec.begin(), vec.end(), ([&](const int& val) { values.emplace_back(val); }));
+ return values;
+ }
+
/**
* Converts a vector of Implicit values to a single Value object.
*/
@@ -394,6 +404,17 @@ public:
vec.begin(), vec.end(), ([&](const ImplicitValue& val) { values.push_back(val); }));
return Value(values);
}
+
+ /**
+ * Converts a vector of Implicit values to a vector of Values.
+ */
+ static std::vector<Value> convertToValues(const std::vector<ImplicitValue>& list) {
+ std::vector<Value> values;
+ for (const ImplicitValue& val : list) {
+ values.push_back(val);
+ }
+ return values;
+ }
};
} // namespace mongo
diff --git a/src/mongo/db/exec/exclusion_projection_executor_test.cpp b/src/mongo/db/exec/exclusion_projection_executor_test.cpp
index cdf7a305bf8..7ee6b00ccf2 100644
--- a/src/mongo/db/exec/exclusion_projection_executor_test.cpp
+++ b/src/mongo/db/exec/exclusion_projection_executor_test.cpp
@@ -272,22 +272,20 @@ TEST(ExclusionProjectionExecutionTest, ShouldNotCreateSubDocIfDottedExcludedFiel
TEST(ExclusionProjectionExecutionTest, ShouldApplyDottedExclusionToEachElementInArray) {
auto exclusion = makeExclusionProjectionWithDefaultPolicies(BSON("a.b" << false));
- std::vector<Value> nestedValues = {
- Value(1),
- Value(Document{}),
- Value(Document{{"b", 1}}),
- Value(Document{{"b", 1}, {"c", 2}}),
- Value(vector<Value>{}),
- Value(vector<Value>{Value(1), Value(Document{{"c", 1}, {"b", 1}})})};
- std::vector<Value> expectedNestedValues = {
- Value(1),
- Value(Document{}),
- Value(Document{}),
- Value(Document{{"c", 2}}),
- Value(vector<Value>{}),
- Value(vector<Value>{Value(1), Value(Document{{"c", 1}})})};
- auto result = exclusion->applyTransformation(Document{{"a", nestedValues}});
- auto expectedResult = Document{{"a", expectedNestedValues}};
+ auto result = exclusion->applyTransformation(Document{{"a",
+ {1,
+ Document{},
+ Document{{"b", 1}},
+ Document{{"b", 1}, {"c", 2}},
+ vector<Value>{},
+ {1, Document{{"c", 1}, {"b", 1}}}}}});
+ auto expectedResult = Document{{"a",
+ {1,
+ Document{},
+ Document{},
+ Document{{"c", 2}},
+ vector<Value>{},
+ {1, Document{{"c", 1}}}}}};
ASSERT_DOCUMENT_EQ(result, expectedResult);
}
@@ -461,18 +459,14 @@ TEST(ExclusionProjectionExecutionTest, ShouldRecurseNestedArraysByDefault) {
auto exclusion = makeExclusionProjectionWithDefaultPolicies(BSON("a.b" << false));
// {a: [1, {b: 2, c: 3}, [{b: 4, c: 5}], {d: 6}]} => {a: [1, {c: 3}, [{c: 5}], {d: 6}]}
- auto result = exclusion->applyTransformation(
- Document{{"a",
- vector<Value>{Value(1),
- Value(Document{{"b", 2}, {"c", 3}}),
- Value(vector<Value>{Value(Document{{"b", 4}, {"c", 5}})}),
- Value(Document{{"d", 6}})}}});
+ auto result = exclusion->applyTransformation(Document{{"a",
+ {1,
+ Document{{"b", 2}, {"c", 3}},
+ vector{Document{{"b", 4}, {"c", 5}}},
+ Document{{"d", 6}}}}});
- auto expectedResult = Document{{"a",
- vector<Value>{Value(1),
- Value(Document{{"c", 3}}),
- Value(vector<Value>{Value(Document{{"c", 5}})}),
- Value(Document{{"d", 6}})}}};
+ auto expectedResult =
+ Document{{"a", {1, Document{{"c", 3}}, vector{Document{{"c", 5}}}, Document{{"d", 6}}}}};
ASSERT_DOCUMENT_EQ(result, expectedResult);
}
@@ -482,19 +476,14 @@ TEST(ExclusionProjectionExecutionTest, ShouldNotRecurseNestedArraysForNoRecurseP
// {a: [1, {b: 2, c: 3}, [{b: 4, c: 5}], {d: 6}]} => {a: [1, {c: 3}, [{b: 4, c: 5}], {d:
// 6}]}
- auto result = exclusion->applyTransformation(
- Document{{"a",
- vector<Value>{Value(1),
- Value(Document{{"b", 2}, {"c", 3}}),
- Value(vector<Value>{Value(Document{{"b", 4}, {"c", 5}})}),
- Value(Document{{"d", 6}})}}});
+ auto result = exclusion->applyTransformation(Document{{"a",
+ {1,
+ Document{{"b", 2}, {"c", 3}},
+ vector{Document{{"b", 4}, {"c", 5}}},
+ Document{{"d", 6}}}}});
- auto expectedResult =
- Document{{"a",
- vector<Value>{Value(1),
- Value(Document{{"c", 3}}),
- Value(vector<Value>{Value(Document{{"b", 4}, {"c", 5}})}),
- Value(Document{{"d", 6}})}}};
+ auto expectedResult = Document{
+ {"a", {1, Document{{"c", 3}}, vector{Document{{"b", 4}, {"c", 5}}}, Document{{"d", 6}}}}};
ASSERT_DOCUMENT_EQ(result, expectedResult);
}
@@ -503,12 +492,11 @@ TEST(ExclusionProjectionExecutionTest, ShouldNotRetainNestedArraysIfNoRecursionN
auto exclusion = makeExclusionProjectionWithNoArrayRecursion(BSON("a" << false));
// {a: [1, {b: 2, c: 3}, [{b: 4, c: 5}], {d: 6}]} => {}
- const auto inputDoc =
- Document{{"a",
- vector<Value>{Value(1),
- Value(Document{{"b", 2}, {"c", 3}}),
- Value(vector<Value>{Value(Document{{"b", 4}, {"c", 5}})}),
- Value(Document{{"d", 6}})}}};
+ const auto inputDoc = Document{{"a",
+ {1,
+ Document{{"b", 2}, {"c", 3}},
+ vector{Document{{"b", 4}, {"c", 5}}},
+ Document{{"d", 6}}}}};
auto result = exclusion->applyTransformation(inputDoc);
const auto expectedResult = Document{};
diff --git a/src/mongo/db/exec/inclusion_projection_executor_test.cpp b/src/mongo/db/exec/inclusion_projection_executor_test.cpp
index 2176652c437..de2464f7f11 100644
--- a/src/mongo/db/exec/inclusion_projection_executor_test.cpp
+++ b/src/mongo/db/exec/inclusion_projection_executor_test.cpp
@@ -549,23 +549,22 @@ TEST_F(InclusionProjectionExecutionTestWithoutFallBackToDefault,
ShouldApplyDottedInclusionToEachElementInArray) {
auto inclusion = makeInclusionProjectionWithDefaultPolicies(BSON("a.b" << true));
- vector<Value> nestedValues = {Value(1),
- Value(Document{}),
- Value(Document{{"b", 1}}),
- Value(Document{{"b", 1}, {"c", 2}}),
- Value(vector<Value>{}),
- Value(vector<Value>{Value(1), Value(Document{{"c", 1}})})};
-
// Drops non-documents and non-arrays. Applies projection to documents, recurses on
// nested arrays.
- vector<Value> expectedNestedValues = {Value(),
- Value(Document{}),
- Value(Document{{"b", 1}}),
- Value(Document{{"b", 1}}),
- Value(vector<Value>{}),
- Value(vector<Value>{Value(), Value(Document{})})};
- auto result = inclusion->applyTransformation(Document{{"a", nestedValues}});
- auto expectedResult = Document{{"a", expectedNestedValues}};
+ auto result = inclusion->applyTransformation(Document{{"a",
+ {1,
+ Document{},
+ Document{{"b", 1}},
+ Document{{"b", 1}, {"c", 2}},
+ vector<Value>{},
+ {1, Document{{"c", 1}}}}}});
+ auto expectedResult = Document{{"a",
+ {Value(),
+ Document{},
+ Document{{"b", 1}},
+ Document{{"b", 1}},
+ vector<Value>{},
+ {Value(), Document{}}}}};
ASSERT_DOCUMENT_EQ(result, expectedResult);
}
@@ -627,22 +626,21 @@ TEST_F(InclusionProjectionExecutionTestWithFallBackToDefault,
auto inclusion =
makeInclusionProjectionWithDefaultPolicies(BSON("a.b" << wrapInLiteral("COMPUTED")));
- vector<Value> nestedValues = {Value(1),
- Value(Document{}),
- Value(Document{{"b", 1}}),
- Value(Document{{"b", 1}, {"c", 2}}),
- Value(vector<Value>{}),
- Value(vector<Value>{Value(1), Value(Document{{"c", 1}})})};
- vector<Value> expectedNestedValues = {
- Value(Document{{"b", "COMPUTED"_sd}}),
- Value(Document{{"b", "COMPUTED"_sd}}),
- Value(Document{{"b", "COMPUTED"_sd}}),
- Value(Document{{"b", "COMPUTED"_sd}}),
- Value(vector<Value>{}),
- Value(vector<Value>{Value(Document{{"b", "COMPUTED"_sd}}),
- Value(Document{{"b", "COMPUTED"_sd}})})};
- auto result = inclusion->applyTransformation(Document{{"a", nestedValues}});
- auto expectedResult = Document{{"a", expectedNestedValues}};
+ auto result = inclusion->applyTransformation(Document{{"a",
+ {1,
+ Document{},
+ Document{{"b", 1}},
+ Document{{"b", 1}, {"c", 2}},
+ vector<Value>{},
+ {1, Document{{"c", 1}}}}}});
+ auto expectedResult =
+ Document{{"a",
+ {Document{{"b", "COMPUTED"_sd}},
+ Document{{"b", "COMPUTED"_sd}},
+ Document{{"b", "COMPUTED"_sd}},
+ Document{{"b", "COMPUTED"_sd}},
+ vector<Value>{},
+ {Document{{"b", "COMPUTED"_sd}}, Document{{"b", "COMPUTED"_sd}}}}}};
ASSERT_DOCUMENT_EQ(result, expectedResult);
}
@@ -651,26 +649,26 @@ TEST_F(InclusionProjectionExecutionTestWithFallBackToDefault,
auto inclusion = makeInclusionProjectionWithDefaultPolicies(
BSON("a.inc" << true << "a.comp" << wrapInLiteral("COMPUTED")));
- vector<Value> nestedValues = {Value(1),
- Value(Document{}),
- Value(Document{{"inc", 1}}),
- Value(Document{{"inc", 1}, {"c", 2}}),
- Value(Document{{"c", 2}, {"inc", 1}}),
- Value(Document{{"inc", 1}, {"c", 2}, {"comp", "original"_sd}}),
- Value(vector<Value>{}),
- Value(vector<Value>{Value(1), Value(Document{{"inc", 1}})})};
- vector<Value> expectedNestedValues = {
- Value(Document{{"comp", "COMPUTED"_sd}}),
- Value(Document{{"comp", "COMPUTED"_sd}}),
- Value(Document{{"inc", 1}, {"comp", "COMPUTED"_sd}}),
- Value(Document{{"inc", 1}, {"comp", "COMPUTED"_sd}}),
- Value(Document{{"inc", 1}, {"comp", "COMPUTED"_sd}}),
- Value(Document{{"inc", 1}, {"comp", "COMPUTED"_sd}}),
- Value(vector<Value>{}),
- Value(vector<Value>{Value(Document{{"comp", "COMPUTED"_sd}}),
- Value(Document{{"inc", 1}, {"comp", "COMPUTED"_sd}})})};
- auto result = inclusion->applyTransformation(Document{{"a", nestedValues}});
- auto expectedResult = Document{{"a", expectedNestedValues}};
+ auto result = inclusion->applyTransformation(
+ Document{{"a",
+ {1,
+ Document{},
+ Document{{"inc", 1}},
+ Document{{"inc", 1}, {"c", 2}},
+ Document{{"c", 2}, {"inc", 1}},
+ Document{{"inc", 1}, {"c", 2}, {"comp", "original"_sd}},
+ vector<Value>{},
+ {1, Document{{"inc", 1}}}}}});
+ auto expectedResult = Document{
+ {"a",
+ {Document{{"comp", "COMPUTED"_sd}},
+ Document{{"comp", "COMPUTED"_sd}},
+ Document{{"inc", 1}, {"comp", "COMPUTED"_sd}},
+ Document{{"inc", 1}, {"comp", "COMPUTED"_sd}},
+ Document{{"inc", 1}, {"comp", "COMPUTED"_sd}},
+ Document{{"inc", 1}, {"comp", "COMPUTED"_sd}},
+ vector<Value>{},
+ {Document{{"comp", "COMPUTED"_sd}}, Document{{"inc", 1}, {"comp", "COMPUTED"_sd}}}}}};
ASSERT_DOCUMENT_EQ(result, expectedResult);
}
@@ -916,18 +914,12 @@ TEST_F(InclusionProjectionExecutionTestWithoutFallBackToDefault,
auto inclusion = makeInclusionProjectionWithDefaultPolicies(BSON("a.b" << true));
// {a: [1, {b: 2, c: 3}, [{b: 4, c: 5}], {d: 6}]} => {a: [{b: 2}, [{b: 4}], {}]}
- auto result = inclusion->applyTransformation(
- Document{{"a",
- vector<Value>{Value(1),
- Value(Document{{"b", 2}, {"c", 3}}),
- Value(vector<Value>{Value(Document{{"b", 4}, {"c", 5}})}),
- Value(Document{{"d", 6}})}}});
+ auto result = inclusion->applyTransformation(Document{
+ {"a",
+ {1, Document{{"b", 2}, {"c", 3}}, {Document{{"b", 4}, {"c", 5}}}, Document{{"d", 6}}}}});
- auto expectedResult = Document{{"a",
- vector<Value>{Value(),
- Value(Document{{"b", 2}}),
- Value(vector<Value>{Value(Document{{"b", 4}})}),
- Value(Document{})}}};
+ auto expectedResult =
+ Document{{"a", {Value(), Document{{"b", 2}}, {Document{{"b", 4}}}, Document{}}}};
ASSERT_DOCUMENT_EQ(result, expectedResult);
}
@@ -937,15 +929,11 @@ TEST_F(InclusionProjectionExecutionTestWithoutFallBackToDefault,
auto inclusion = makeInclusionProjectionWithNoArrayRecursion(BSON("a.b" << true));
// {a: [1, {b: 2, c: 3}, [{b: 4, c: 5}], {d: 6}]} => {a: [{b: 2}, {}]}
- auto result = inclusion->applyTransformation(
- Document{{"a",
- vector<Value>{Value(1),
- Value(Document{{"b", 2}, {"c", 3}}),
- Value(vector<Value>{Value(Document{{"b", 4}, {"c", 5}})}),
- Value(Document{{"d", 6}})}}});
+ auto result = inclusion->applyTransformation(Document{
+ {"a",
+ {1, Document{{"b", 2}, {"c", 3}}, {Document{{"b", 4}, {"c", 5}}}, Document{{"d", 6}}}}});
- auto expectedResult = Document{
- {"a", vector<Value>{Value(), Value(Document{{"b", 2}}), Value(), Value(Document{})}}};
+ auto expectedResult = Document{{"a", {Value(), Document{{"b", 2}}, Value(), Document{}}}};
ASSERT_DOCUMENT_EQ(result, expectedResult);
}
@@ -955,12 +943,9 @@ TEST_F(InclusionProjectionExecutionTestWithoutFallBackToDefault,
auto inclusion = makeInclusionProjectionWithNoArrayRecursion(BSON("a" << true));
// {a: [1, {b: 2, c: 3}, [{b: 4, c: 5}], {d: 6}]} => [output doc identical to input]
- const auto inputDoc =
- Document{{"a",
- vector<Value>{Value(1),
- Value(Document{{"b", 2}, {"c", 3}}),
- Value(vector<Value>{Value(Document{{"b", 4}, {"c", 5}})}),
- Value(Document{{"d", 6}})}}};
+ const auto inputDoc = Document{
+ {"a",
+ {1, Document{{"b", 2}, {"c", 3}}, {Document{{"b", 4}, {"c", 5}}}, Document{{"d", 6}}}}};
auto result = inclusion->applyTransformation(inputDoc);
const auto& expectedResult = inputDoc;
@@ -973,22 +958,21 @@ TEST_F(InclusionProjectionExecutionTestWithFallBackToDefault,
auto inclusion =
makeInclusionProjectionWithDefaultPolicies(BSON("a.b" << wrapInLiteral("COMPUTED")));
- vector<Value> nestedValues = {Value(1),
- Value(Document{}),
- Value(Document{{"b", 1}}),
- Value(Document{{"b", 1}, {"c", 2}}),
- Value(vector<Value>{}),
- Value(vector<Value>{Value(1), Value(Document{{"c", 1}})})};
- vector<Value> expectedNestedValues = {
- Value(Document{{"b", "COMPUTED"_sd}}),
- Value(Document{{"b", "COMPUTED"_sd}}),
- Value(Document{{"b", "COMPUTED"_sd}}),
- Value(Document{{"b", "COMPUTED"_sd}}),
- Value(vector<Value>{}),
- Value(vector<Value>{Value(Document{{"b", "COMPUTED"_sd}}),
- Value(Document{{"b", "COMPUTED"_sd}})})};
- auto result = inclusion->applyTransformation(Document{{"a", nestedValues}});
- auto expectedResult = Document{{"a", expectedNestedValues}};
+ auto result = inclusion->applyTransformation(Document{{"a",
+ {1,
+ Document{},
+ Document{{"b", 1}},
+ Document{{"b", 1}, {"c", 2}},
+ vector<Value>{},
+ {1, Document{{"c", 1}}}}}});
+ auto expectedResult =
+ Document{{"a",
+ {Document{{"b", "COMPUTED"_sd}},
+ Document{{"b", "COMPUTED"_sd}},
+ Document{{"b", "COMPUTED"_sd}},
+ Document{{"b", "COMPUTED"_sd}},
+ vector<Value>{},
+ {Document{{"b", "COMPUTED"_sd}}, Document{{"b", "COMPUTED"_sd}}}}}};
ASSERT_DOCUMENT_EQ(result, expectedResult);
}
@@ -1002,22 +986,20 @@ TEST_F(InclusionProjectionExecutionTestWithFallBackToDefault,
// of the array and all nested arrays individually. With kDoNotRecurseNestedArrays, the
// nested arrays are replaced rather than being traversed, in exactly the same way as
// scalar values.
- vector<Value> nestedValues = {Value(1),
- Value(Document{}),
- Value(Document{{"b", 1}}),
- Value(Document{{"b", 1}, {"c", 2}}),
- Value(vector<Value>{}),
- Value(vector<Value>{Value(1), Value(Document{{"c", 1}})})};
-
- vector<Value> expectedNestedValues = {Value(Document{{"b", "COMPUTED"_sd}}),
- Value(Document{{"b", "COMPUTED"_sd}}),
- Value(Document{{"b", "COMPUTED"_sd}}),
- Value(Document{{"b", "COMPUTED"_sd}}),
- Value(Document{{"b", "COMPUTED"_sd}}),
- Value(Document{{"b", "COMPUTED"_sd}})};
-
- auto result = inclusion->applyTransformation(Document{{"a", nestedValues}});
- auto expectedResult = Document{{"a", expectedNestedValues}};
+ auto result = inclusion->applyTransformation(Document{{"a",
+ {1,
+ Document{},
+ Document{{"b", 1}},
+ Document{{"b", 1}, {"c", 2}},
+ vector<Value>{},
+ {1, Document{{"c", 1}}}}}});
+ auto expectedResult = Document{{"a",
+ {Document{{"b", "COMPUTED"_sd}},
+ Document{{"b", "COMPUTED"_sd}},
+ Document{{"b", "COMPUTED"_sd}},
+ Document{{"b", "COMPUTED"_sd}},
+ Document{{"b", "COMPUTED"_sd}},
+ Document{{"b", "COMPUTED"_sd}}}}};
ASSERT_DOCUMENT_EQ(result, expectedResult);
}
} // namespace
diff --git a/src/mongo/db/index/sort_key_generator_test.cpp b/src/mongo/db/index/sort_key_generator_test.cpp
index 17c66fe7d59..4fc3694974a 100644
--- a/src/mongo/db/index/sort_key_generator_test.cpp
+++ b/src/mongo/db/index/sort_key_generator_test.cpp
@@ -53,46 +53,42 @@ std::unique_ptr<SortKeyGenerator> makeSortKeyGen(const BSONObj& sortSpec,
TEST(SortKeyGeneratorTest, ExtractNumberKeyForNonCompoundSortNonNested) {
auto sortKeyGen = makeSortKeyGen(BSON("a" << 1), nullptr);
- auto sortKey = sortKeyGen->computeSortKeyFromDocument(Document{{"_id", {5}}, {"a", {5}}});
+ auto sortKey = sortKeyGen->computeSortKeyFromDocument(Document{{"_id", 5}, {"a", 5}});
ASSERT_VALUE_EQ(sortKey, Value{5});
}
TEST(SortKeyGeneratorTest, ExtractNumberKeyFromDocWithSeveralFields) {
auto sortKeyGen = makeSortKeyGen(BSON("a" << 1), nullptr);
auto sortKey = sortKeyGen->computeSortKeyFromDocument(
- Document{{"_id", {0}}, {"z", {10}}, {"a", {6}}, {"b", {16}}});
+ Document{{"_id", 0}, {"z", 10}, {"a", 6}, {"b", 16}});
ASSERT_VALUE_EQ(sortKey, Value{6});
}
TEST(SortKeyGeneratorTest, ExtractStringKeyNonCompoundNonNested) {
auto sortKeyGen = makeSortKeyGen(BSON("a" << 1), nullptr);
auto sortKey = sortKeyGen->computeSortKeyFromDocument(
- Document{{"_id", {0}}, {"z", {"thing1"_sd}}, {"a", {"thing2"_sd}}, {"b", {16}}});
+ Document{{"_id", 0}, {"z", "thing1"_sd}, {"a", "thing2"_sd}, {"b", 16}});
ASSERT_VALUE_EQ(sortKey, Value{"thing2"_sd});
}
TEST(SortKeyGeneratorTest, CompoundSortPattern) {
auto sortKeyGen = makeSortKeyGen(BSON("a" << 1 << "b" << 1), nullptr);
- auto sortKey = sortKeyGen->computeSortKeyFromDocument(Document{
- {"_id", {0}}, {"z", {"thing1"_sd}}, {"a", {99}}, {"c", Document{{"a", {4}}}}, {"b", {16}}});
+ auto sortKey = sortKeyGen->computeSortKeyFromDocument(
+ Document{{"_id", 0}, {"z", "thing1"_sd}, {"a", 99}, {"c", Document{{"a", 4}}}, {"b", 16}});
ASSERT_VALUE_EQ(sortKey, (Value{std::vector<Value>{Value{99}, Value{16}}}));
}
TEST(SortKeyGeneratorTest, CompoundSortPatternWithDottedPath) {
auto sortKeyGen = makeSortKeyGen(BSON("c.a" << 1 << "b" << 1), nullptr);
- auto sortKey = sortKeyGen->computeSortKeyFromDocument(Document{
- {"_id", {0}}, {"z", {"thing1"_sd}}, {"a", {99}}, {"c", Document{{"a", {4}}}}, {"b", {16}}});
+ auto sortKey = sortKeyGen->computeSortKeyFromDocument(
+ Document{{"_id", 0}, {"z", "thing1"_sd}, {"a", 99}, {"c", Document{{"a", 4}}}, {"b", 16}});
ASSERT_VALUE_EQ(sortKey, (Value{std::vector<Value>{Value{4}, Value{16}}}));
}
TEST(SortKeyGeneratorTest, CompoundPatternLeadingFieldIsArray) {
auto sortKeyGen = makeSortKeyGen(BSON("c" << 1 << "b" << 1), nullptr);
- auto sortKey = sortKeyGen->computeSortKeyFromDocument(
- Document{{"_id", {0}},
- {"z", {"thing1"_sd}},
- {"a", {99}},
- {"c", Value{std::vector<Value>{Value{2}, Value{4}, Value{1}}}},
- {"b", {16}}});
+ auto sortKey = sortKeyGen->computeSortKeyFromDocument(Document{
+ {"_id", 0}, {"z", "thing1"_sd}, {"a", 99}, {"c", std::vector{2, 4, 1}}, {"b", 16}});
ASSERT_VALUE_EQ(sortKey, (Value{std::vector<Value>{Value{1}, Value{16}}}));
}
@@ -100,7 +96,7 @@ TEST(SortKeyGeneratorTest, ExtractStringSortKeyWithCollatorUsesComparisonKey) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
auto sortKeyGen = makeSortKeyGen(BSON("a" << 1), &collator);
auto sortKey = sortKeyGen->computeSortKeyFromDocument(
- Document{{"_id", {0}}, {"z", {"thing1"_sd}}, {"a", {"thing2"_sd}}, {"b", {16}}});
+ Document{{"_id", 0}, {"z", "thing1"_sd}, {"a", "thing2"_sd}, {"b", 16}});
ASSERT_VALUE_EQ(sortKey, Value{"2gniht"_sd});
}
@@ -108,14 +104,14 @@ TEST(SortKeyGeneratorTest, CollatorHasNoEffectWhenExtractingNonStringSortKey) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
auto sortKeyGen = makeSortKeyGen(BSON("a" << 1), &collator);
auto sortKey = sortKeyGen->computeSortKeyFromDocument(
- Document{{"_id", {0}}, {"z", {10}}, {"a", {6}}, {"b", {16}}});
+ Document{{"_id", 0}, {"z", 10}, {"a", 6}, {"b", 16}});
ASSERT_VALUE_EQ(sortKey, Value{6});
}
TEST(SortKeyGeneratorTest, SortKeyGenerationForArraysChoosesCorrectKey) {
auto sortKeyGen = makeSortKeyGen(BSON("a" << -1), nullptr);
- auto sortKey = sortKeyGen->computeSortKeyFromDocument(Document{
- {"_id", {0}}, {"a", Value{std::vector<Value>{Value{1}, Value{2}, Value{3}, Value{4}}}}});
+ auto sortKey =
+ sortKeyGen->computeSortKeyFromDocument(Document{{"_id", 0}, {"a", {1, 2, 3, 4}}});
ASSERT_VALUE_EQ(sortKey, Value{4});
}
@@ -123,49 +119,48 @@ TEST(SortKeyGeneratorTest, EnsureSortKeyGenerationForArraysRespectsCollation) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
auto sortKeyGen = makeSortKeyGen(BSON("a" << 1), &collator);
auto sortKey = sortKeyGen->computeSortKeyFromDocument(
- Document{{"_id", {0}},
- {"a",
- Value{std::vector<Value>{
- Value{"aaz"_sd}, Value{"zza"_sd}, Value{"yya"_sd}, Value{"zzb"_sd}}}}});
+ Document{{"_id", {0}}, {"a", {"aaz"_sd, "zza"_sd, "yya"_sd, "zzb"_sd}}});
ASSERT_VALUE_EQ(sortKey, Value{"ayy"_sd});
}
TEST(SortKeyGeneratorTest, SortKeyGenerationForArraysRespectsCompoundOrdering) {
auto sortKeyGen = makeSortKeyGen(BSON("a.b" << 1 << "a.c" << -1), nullptr);
auto sortKey = sortKeyGen->computeSortKeyFromDocument(
- Document{fromjson("{_id: 0, a: [{b: 1, c: 0}, {b: 0, c: 3}, {b: 0, c: 1}]}")});
+ Document{{"_id", 0},
+ {"a",
+ std::vector{Document{{"b", 1}, {"c", 0}},
+ Document{{"b", 0}, {"c", 3}},
+ Document{{"b", 0}, {"c", 1}}}}});
ASSERT_VALUE_EQ(sortKey, (Value{std::vector<Value>{Value{0}, Value{3}}}));
}
TEST(SortKeyGeneratorTest, SortKeyGenerationForMissingField) {
auto sortKeyGen = makeSortKeyGen(BSON("b" << 1), nullptr);
- auto sortKey = sortKeyGen->computeSortKeyFromDocument(Document{{"a", Value{1}}});
+ auto sortKey = sortKeyGen->computeSortKeyFromDocument(Document{{"a", {1}}});
ASSERT_VALUE_EQ(sortKey, Value{BSONNULL});
}
TEST(SortKeyGeneratorTest, SortKeyGenerationForMissingFieldInCompoundSortPattern) {
auto sortKeyGen = makeSortKeyGen(BSON("a" << 1 << "b" << 1), nullptr);
- auto sortKey = sortKeyGen->computeSortKeyFromDocument(Document{{"b", Value{1}}});
+ auto sortKey = sortKeyGen->computeSortKeyFromDocument(Document{{"b", {1}}});
ASSERT_VALUE_EQ(sortKey, (Value{std::vector<Value>{Value{BSONNULL}, Value{1}}}));
}
TEST(SortKeyGeneratorTest, SortKeyGenerationForMissingFieldInEmbeddedDocument) {
auto sortKeyGen = makeSortKeyGen(BSON("a.b" << 1), nullptr);
- auto sortKey =
- sortKeyGen->computeSortKeyFromDocument(Document{{"a", Value{Document{{"c", Value{1}}}}}});
+ auto sortKey = sortKeyGen->computeSortKeyFromDocument(Document{{"a", Document{{"c", 1}}}});
ASSERT_VALUE_EQ(sortKey, Value{BSONNULL});
}
TEST(SortKeyGeneratorTest, SortKeyGenerationForMissingFieldInArrayElement) {
auto sortKeyGen = makeSortKeyGen(BSON("a.b" << 1), nullptr);
- auto sortKey = sortKeyGen->computeSortKeyFromDocument(
- Document{{"a", Value{std::vector<Value>{Value{Document{}}}}}});
+ auto sortKey = sortKeyGen->computeSortKeyFromDocument(Document{{"a", std::vector{Document{}}}});
ASSERT_VALUE_EQ(sortKey, Value{BSONNULL});
}
TEST(SortKeyGeneratorTest, SortKeyGenerationForInvalidPath) {
auto sortKeyGen = makeSortKeyGen(BSON("a.b" << 1), nullptr);
- auto sortKey = sortKeyGen->computeSortKeyFromDocument(Document{{"a", Value{1}}});
+ auto sortKey = sortKeyGen->computeSortKeyFromDocument(Document{{"a", 1}});
ASSERT_VALUE_EQ(sortKey, Value{BSONNULL});
}
diff --git a/src/mongo/db/pipeline/aggregation_request_test.cpp b/src/mongo/db/pipeline/aggregation_request_test.cpp
index 8642432720f..225be1a950e 100644
--- a/src/mongo/db/pipeline/aggregation_request_test.cpp
+++ b/src/mongo/db/pipeline/aggregation_request_test.cpp
@@ -158,7 +158,7 @@ TEST(AggregationRequestTest, ShouldOnlySerializeRequiredFieldsIfNoOptionalFields
auto expectedSerialization =
Document{{AggregationRequest::kCommandName, nss.coll()},
- {AggregationRequest::kPipelineName, Value(std::vector<Value>{})},
+ {AggregationRequest::kPipelineName, std::vector<Value>{}},
{AggregationRequest::kCursorName, Value(kDefaultCursorOptionDocument)}};
ASSERT_DOCUMENT_EQ(request.serializeToCommandObj(), expectedSerialization);
}
@@ -181,7 +181,7 @@ TEST(AggregationRequestTest, ShouldNotSerializeOptionalValuesIfEquivalentToDefau
auto expectedSerialization =
Document{{AggregationRequest::kCommandName, nss.coll()},
- {AggregationRequest::kPipelineName, Value(std::vector<Value>{})},
+ {AggregationRequest::kPipelineName, std::vector<Value>{}},
{AggregationRequest::kCursorName, Value(kDefaultCursorOptionDocument)}};
ASSERT_DOCUMENT_EQ(request.serializeToCommandObj(), expectedSerialization);
}
@@ -216,7 +216,7 @@ TEST(AggregationRequestTest, ShouldSerializeOptionalValuesIfSet) {
auto expectedSerialization =
Document{{AggregationRequest::kCommandName, nss.coll()},
- {AggregationRequest::kPipelineName, Value(std::vector<Value>{})},
+ {AggregationRequest::kPipelineName, std::vector<Value>{}},
{AggregationRequest::kAllowDiskUseName, true},
{AggregationRequest::kFromMongosName, true},
{AggregationRequest::kNeedsMergeName, true},
@@ -242,7 +242,7 @@ TEST(AggregationRequestTest, ShouldSerializeBatchSizeIfSetAndExplainFalse) {
auto expectedSerialization =
Document{{AggregationRequest::kCommandName, nss.coll()},
- {AggregationRequest::kPipelineName, Value(std::vector<Value>{})},
+ {AggregationRequest::kPipelineName, std::vector<Value>{}},
{AggregationRequest::kCursorName,
Value(Document({{AggregationRequest::kBatchSizeName, 10}}))}};
ASSERT_DOCUMENT_EQ(request.serializeToCommandObj(), expectedSerialization);
@@ -254,7 +254,7 @@ TEST(AggregationRequestTest, ShouldSerialiseAggregateFieldToOneIfCollectionIsAgg
auto expectedSerialization =
Document{{AggregationRequest::kCommandName, 1},
- {AggregationRequest::kPipelineName, Value(std::vector<Value>{})},
+ {AggregationRequest::kPipelineName, std::vector<Value>{}},
{AggregationRequest::kCursorName,
Value(Document({{AggregationRequest::kBatchSizeName,
AggregationRequest::kDefaultBatchSize}}))}};
@@ -287,10 +287,9 @@ TEST(AggregationRequestTest, ShouldNotSerializeBatchSizeWhenExplainSet) {
request.setBatchSize(10);
request.setExplain(ExplainOptions::Verbosity::kQueryPlanner);
- auto expectedSerialization =
- Document{{AggregationRequest::kCommandName, nss.coll()},
- {AggregationRequest::kPipelineName, Value(std::vector<Value>{})},
- {AggregationRequest::kCursorName, Value(Document())}};
+ auto expectedSerialization = Document{{AggregationRequest::kCommandName, nss.coll()},
+ {AggregationRequest::kPipelineName, std::vector<Value>{}},
+ {AggregationRequest::kCursorName, Value(Document())}};
ASSERT_DOCUMENT_EQ(request.serializeToCommandObj(), expectedSerialization);
}
diff --git a/src/mongo/db/pipeline/document_path_support_test.cpp b/src/mongo/db/pipeline/document_path_support_test.cpp
index f870a317f22..5e966e08a75 100644
--- a/src/mongo/db/pipeline/document_path_support_test.cpp
+++ b/src/mongo/db/pipeline/document_path_support_test.cpp
@@ -70,7 +70,7 @@ TEST(VisitAllValuesAtPathTest, NestedObjectWithEmptyArrayValue) {
TEST(VisitAllValuesAtPathTest, NestedObjectWithSingletonArrayValue) {
auto values = kDefaultValueComparator.makeUnorderedValueSet();
auto callback = [&values](const Value& val) { values.insert(val); };
- Document doc{{"a", Document{{"b", vector<Value>{Value(1)}}}}};
+ Document doc{{"a", Document{{"b", vector{1}}}}};
visitAllValuesAtPath(doc, FieldPath("a.b"), callback);
ASSERT_EQ(values.size(), 1UL);
ASSERT_EQ(values.count(Value(1)), 1UL);
@@ -79,7 +79,7 @@ TEST(VisitAllValuesAtPathTest, NestedObjectWithSingletonArrayValue) {
TEST(VisitAllValuesAtPathTest, NestedObjectWithArrayValue) {
auto values = kDefaultValueComparator.makeUnorderedValueSet();
auto callback = [&values](const Value& val) { values.insert(val); };
- Document doc{{"a", Document{{"b", vector<Value>{Value(1), Value(2), Value(3)}}}}};
+ Document doc{{"a", Document{{"b", vector{1, 2, 3}}}}};
visitAllValuesAtPath(doc, FieldPath("a.b"), callback);
ASSERT_EQ(values.size(), 3UL);
ASSERT_EQ(values.count(Value(1)), 1UL);
@@ -103,9 +103,9 @@ TEST(VisitAllValuesAtPathTest, ObjectWithArrayOfSubobjectsWithArrayValues) {
auto values = kDefaultValueComparator.makeUnorderedValueSet();
auto callback = [&values](const Value& val) { values.insert(val); };
Document doc{{"a",
- vector<Document>{Document{{"b", vector<Value>{Value(1), Value(2)}}},
- Document{{"b", vector<Value>{Value(2), Value(3)}}},
- Document{{"b", vector<Value>{Value(3), Value(1)}}}}}};
+ vector<Document>{Document{{"b", vector{1, 2}}},
+ Document{{"b", vector{2, 3}}},
+ Document{{"b", vector{3, 1}}}}}};
visitAllValuesAtPath(doc, FieldPath("a.b"), callback);
ASSERT_EQ(values.size(), 3UL);
ASSERT_EQ(values.count(Value(1)), 1UL);
@@ -151,7 +151,7 @@ TEST(VisitAllValuesAtPathTest, AcceptsNumericFieldNames) {
TEST(VisitAllValuesAtPathTest, UsesNumericFieldNameToExtractElementFromArray) {
auto values = kDefaultValueComparator.makeUnorderedValueSet();
auto callback = [&values](const Value& val) { values.insert(val); };
- Document doc{{"a", vector<Value>{Value(1), Value(Document{{"0", 1}})}}};
+ Document doc{{"a", {1, Document{{"0", 1}}}}};
visitAllValuesAtPath(doc, FieldPath("a.0"), callback);
ASSERT_EQ(values.size(), 1UL);
ASSERT_EQ(values.count(Value(1)), 1UL);
@@ -160,10 +160,7 @@ TEST(VisitAllValuesAtPathTest, UsesNumericFieldNameToExtractElementFromArray) {
TEST(VisitAllValuesAtPathTest, TreatsNegativeIndexAsFieldName) {
auto values = kDefaultValueComparator.makeUnorderedValueSet();
auto callback = [&values](const Value& val) { values.insert(val); };
- Document doc{
- {"a",
- vector<Value>{
- Value(0), Value(1), Value(Document{{"-1", "target"_sd}}), Value(Document{{"b", 3}})}}};
+ Document doc{{"a", {0, 1, Document{{"-1", "target"_sd}}, Document{{"b", 3}}}}};
visitAllValuesAtPath(doc, FieldPath("a.-1"), callback);
ASSERT_EQ(values.size(), 1UL);
ASSERT_EQ(values.count(Value("target"_sd)), 1UL);
@@ -172,8 +169,7 @@ TEST(VisitAllValuesAtPathTest, TreatsNegativeIndexAsFieldName) {
TEST(VisitAllValuesAtPathTest, ExtractsNoValuesFromOutOfBoundsIndex) {
auto values = kDefaultValueComparator.makeUnorderedValueSet();
auto callback = [&values](const Value& val) { values.insert(val); };
- Document doc{
- {"a", vector<Value>{Value(1), Value(Document{{"b", 2}}), Value(Document{{"10", 3}})}}};
+ Document doc{{"a", {1, Document{{"b", 2}}, Document{{"10", 3}}}}};
visitAllValuesAtPath(doc, FieldPath("a.10"), callback);
ASSERT_EQ(values.size(), 0UL);
}
@@ -181,10 +177,7 @@ TEST(VisitAllValuesAtPathTest, ExtractsNoValuesFromOutOfBoundsIndex) {
TEST(VisitAllValuesAtPathTest, DoesNotTreatHexStringAsIndexSpecification) {
auto values = kDefaultValueComparator.makeUnorderedValueSet();
auto callback = [&values](const Value& val) { values.insert(val); };
- Document doc{{"a",
- vector<Value>{Value(1),
- Value(Document{{"0x2", 2}}),
- Value(Document{{"NOT THIS ONE", 3}})}}};
+ Document doc{{"a", {1, Document{{"0x2", 2}}, Document{{"NOT THIS ONE", 3}}}}};
visitAllValuesAtPath(doc, FieldPath("a.0x2"), callback);
ASSERT_EQ(values.size(), 1UL);
ASSERT_EQ(values.count(Value(2)), 1UL);
@@ -193,9 +186,7 @@ TEST(VisitAllValuesAtPathTest, DoesNotTreatHexStringAsIndexSpecification) {
TEST(VisitAllValuesAtPathTest, DoesNotAcceptLeadingPlusAsArrayIndex) {
auto values = kDefaultValueComparator.makeUnorderedValueSet();
auto callback = [&values](const Value& val) { values.insert(val); };
- Document doc{{"a",
- vector<Value>{
- Value(1), Value(Document{{"+2", 2}}), Value(Document{{"NOT THIS ONE", 3}})}}};
+ Document doc{{"a", {1, Document{{"+2", 2}}, Document{{"NOT THIS ONE", 3}}}}};
visitAllValuesAtPath(doc, FieldPath("a.+2"), callback);
ASSERT_EQ(values.size(), 1UL);
ASSERT_EQ(values.count(Value(2)), 1UL);
@@ -204,10 +195,7 @@ TEST(VisitAllValuesAtPathTest, DoesNotAcceptLeadingPlusAsArrayIndex) {
TEST(VisitAllValuesAtPathTest, DoesNotAcceptTrailingCharactersForArrayIndex) {
auto values = kDefaultValueComparator.makeUnorderedValueSet();
auto callback = [&values](const Value& val) { values.insert(val); };
- Document doc{{"a",
- vector<Value>{Value(1),
- Value(Document{{"2xyz", 2}}),
- Value(Document{{"NOT THIS ONE", 3}})}}};
+ Document doc{{"a", {1, Document{{"2xyz", 2}}, Document{{"NOT THIS ONE", 3}}}}};
visitAllValuesAtPath(doc, FieldPath("a.2xyz"), callback);
ASSERT_EQ(values.size(), 1UL);
ASSERT_EQ(values.count(Value(2)), 1UL);
@@ -216,10 +204,7 @@ TEST(VisitAllValuesAtPathTest, DoesNotAcceptTrailingCharactersForArrayIndex) {
TEST(VisitAllValuesAtPathTest, DoesNotAcceptNonDigitsForArrayIndex) {
auto values = kDefaultValueComparator.makeUnorderedValueSet();
auto callback = [&values](const Value& val) { values.insert(val); };
- Document doc{{"a",
- vector<Value>{Value(1),
- Value(Document{{"2x4", 2}}),
- Value(Document{{"NOT THIS ONE", 3}})}}};
+ Document doc{{"a", {1, Document{{"2x4", 2}}, Document{{"NOT THIS ONE", 3}}}}};
visitAllValuesAtPath(doc, FieldPath("a.2x4"), callback);
ASSERT_EQ(values.size(), 1UL);
ASSERT_EQ(values.count(Value(2)), 1UL);
@@ -229,8 +214,7 @@ TEST(VisitAllValuesAtPathTest,
DoesExtractNestedValuesFromWithinArraysTraversedWithPositionalPaths) {
auto values = kDefaultValueComparator.makeUnorderedValueSet();
auto callback = [&values](const Value& val) { values.insert(val); };
- Document doc{
- {"a", vector<Value>{Value(1), Value(Document{{"2", 2}}), Value(Document{{"target", 3}})}}};
+ Document doc{{"a", {1, Document{{"2", 2}}, Document{{"target", 3}}}}};
visitAllValuesAtPath(doc, FieldPath("a.2.target"), callback);
ASSERT_EQ(values.size(), 1UL);
ASSERT_EQ(values.count(Value(3)), 1UL);
@@ -275,7 +259,7 @@ TEST(VisitAllValuesAtPathTest, DoesNotAddMissingValueToResults) {
TEST(VisitAllValuesAtPathTest, DoesNotAddMissingValueWithinArrayToResults) {
auto values = kDefaultValueComparator.makeUnorderedValueSet();
auto callback = [&values](const Value& val) { values.insert(val); };
- Document doc{{"a", vector<Value>{Value(1), Value(), Value(2)}}};
+ Document doc{{"a", {1, Value(), 2}}};
visitAllValuesAtPath(doc, FieldPath("a"), callback);
ASSERT_EQ(values.size(), 2UL);
ASSERT_EQ(values.count(Value(1)), 1UL);
diff --git a/src/mongo/db/pipeline/document_source_change_stream_test.cpp b/src/mongo/db/pipeline/document_source_change_stream_test.cpp
index 678ef85676f..c4ddc661be0 100644
--- a/src/mongo/db/pipeline/document_source_change_stream_test.cpp
+++ b/src/mongo/db/pipeline/document_source_change_stream_test.cpp
@@ -865,13 +865,13 @@ TEST_F(ChangeStreamStageTest, TransformRemoveFields) {
{DSChangeStream::kOperationTypeField, DSChangeStream::kUpdateOpType},
{DSChangeStream::kClusterTimeField, kDefaultTs},
{DSChangeStream::kNamespaceField, D{{"db", nss.db()}, {"coll", nss.coll()}}},
- {DSChangeStream::kDocumentKeyField, D{{{"_id", 1}, {"x", 2}}}},
+ {DSChangeStream::kDocumentKeyField, Document{{"_id", 1}, {"x", 2}}},
{
"updateDescription",
- D{{"updatedFields", D{}}, {"removedFields", vector<V>{V("y"_sd)}}},
+ D{{"updatedFields", D{}}, {"removedFields", {"y"_sd}}},
}};
checkTransformation(removeField, expectedRemoveField);
-}
+} // namespace
TEST_F(ChangeStreamStageTest, TransformReplace) {
BSONObj o = BSON("_id" << 1 << "x" << 2 << "y" << 1);
@@ -2014,10 +2014,10 @@ TEST_F(ChangeStreamStageDBTest, TransformRemoveFields) {
{DSChangeStream::kOperationTypeField, DSChangeStream::kUpdateOpType},
{DSChangeStream::kClusterTimeField, kDefaultTs},
{DSChangeStream::kNamespaceField, D{{"db", nss.db()}, {"coll", nss.coll()}}},
- {DSChangeStream::kDocumentKeyField, D{{{"_id", 1}, {"x", 2}}}},
+ {DSChangeStream::kDocumentKeyField, D{{"_id", 1}, {"x", 2}}},
{
"updateDescription",
- D{{"updatedFields", D{}}, {"removedFields", vector<V>{V("y"_sd)}}},
+ D{{"updatedFields", D{}}, {"removedFields", {"y"_sd}}},
}};
checkTransformation(removeField, expectedRemoveField);
}
diff --git a/src/mongo/db/pipeline/document_source_graph_lookup_test.cpp b/src/mongo/db/pipeline/document_source_graph_lookup_test.cpp
index c59ed9c2ea4..3b1299ec9be 100644
--- a/src/mongo/db/pipeline/document_source_graph_lookup_test.cpp
+++ b/src/mongo/db/pipeline/document_source_graph_lookup_test.cpp
@@ -491,8 +491,7 @@ TEST_F(DocumentSourceGraphLookUpTest, ShouldExpandArraysAtEndOfConnectFromField)
* \ /
* `> 3 '
*/
- Document startDoc{{"_id", 0},
- {"to", std::vector<Value>{Value(1), Value(2), Value(3)}}}; // Note the array.
+ Document startDoc{{"_id", 0}, {"to", std::vector{1, 2, 3}}};
Document middle1{{"_id", 1}, {"to", 4}};
Document middle2{{"_id", 2}, {"to", 4}};
Document middle3{{"_id", 3}, {"to", 4}};
diff --git a/src/mongo/db/pipeline/document_source_lookup.cpp b/src/mongo/db/pipeline/document_source_lookup.cpp
index 94a4071d4ad..78e4d59d077 100644
--- a/src/mongo/db/pipeline/document_source_lookup.cpp
+++ b/src/mongo/db/pipeline/document_source_lookup.cpp
@@ -732,10 +732,10 @@ void DocumentSourceLookUp::serializeToArray(
{"pipeline", pipeline}}}};
} else {
doc = Document{{getSourceName(),
- {Document{{"from", fromValue},
- {"as", _as.fullPath()},
- {"localField", _localField->fullPath()},
- {"foreignField", _foreignField->fullPath()}}}}};
+ Document{{"from", fromValue},
+ {"as", _as.fullPath()},
+ {"localField", _localField->fullPath()},
+ {"foreignField", _foreignField->fullPath()}}}};
}
MutableDocument output(doc);
diff --git a/src/mongo/db/pipeline/document_source_lookup_test.cpp b/src/mongo/db/pipeline/document_source_lookup_test.cpp
index baa1fd032d0..5d8bedf72b4 100644
--- a/src/mongo/db/pipeline/document_source_lookup_test.cpp
+++ b/src/mongo/db/pipeline/document_source_lookup_test.cpp
@@ -726,17 +726,15 @@ TEST_F(DocumentSourceLookUpTest, ShouldPropagatePauses) {
auto next = lookup->getNext();
ASSERT_TRUE(next.isAdvanced());
- ASSERT_DOCUMENT_EQ(
- next.releaseDocument(),
- (Document{{"foreignId", 0}, {"foreignDocs", vector<Value>{Value(Document{{"_id", 0}})}}}));
+ ASSERT_DOCUMENT_EQ(next.releaseDocument(),
+ (Document{{"foreignId", 0}, {"foreignDocs", {Document{{"_id", 0}}}}}));
ASSERT_TRUE(lookup->getNext().isPaused());
next = lookup->getNext();
ASSERT_TRUE(next.isAdvanced());
- ASSERT_DOCUMENT_EQ(
- next.releaseDocument(),
- (Document{{"foreignId", 1}, {"foreignDocs", vector<Value>{Value(Document{{"_id", 1}})}}}));
+ ASSERT_DOCUMENT_EQ(next.releaseDocument(),
+ (Document{{"foreignId", 1}, {"foreignDocs", {Document{{"_id", 1}}}}}));
ASSERT_TRUE(lookup->getNext().isPaused());
diff --git a/src/mongo/db/pipeline/expression_test.cpp b/src/mongo/db/pipeline/expression_test.cpp
index e1eeb44d3d2..c5deffd22e8 100644
--- a/src/mongo/db/pipeline/expression_test.cpp
+++ b/src/mongo/db/pipeline/expression_test.cpp
@@ -67,7 +67,7 @@ static Value evaluateExpression(const string& expressionName,
const vector<ImplicitValue>& operands) {
auto expCtx = ExpressionContextForTest{};
VariablesParseState vps = expCtx.variablesParseState;
- const BSONObj obj = BSON(expressionName << ImplicitValue::convertToValue(operands));
+ const BSONObj obj = BSON(expressionName << Value(ImplicitValue::convertToValues(operands)));
auto expression = Expression::parseExpression(&expCtx, obj, vps);
Value result = expression->evaluate({}, &expCtx.variables);
return result;
@@ -80,14 +80,14 @@ static Value evaluateExpression(const string& expressionName,
*/
static void assertExpectedResults(
const string& expression,
- initializer_list<pair<vector<ImplicitValue>, ImplicitValue>> operations) {
+ initializer_list<pair<initializer_list<ImplicitValue>, ImplicitValue>> operations) {
for (auto&& op : operations) {
try {
Value result = evaluateExpression(expression, op.first);
ASSERT_VALUE_EQ(op.second, result);
ASSERT_EQUALS(op.second.getType(), result.getType());
} catch (...) {
- LOGV2(24188, "failed", "argument"_attr = ImplicitValue::convertToValue(op.first));
+ LOGV2(24188, "failed", "argument"_attr = ImplicitValue::convertToValues(op.first));
throw;
}
}
@@ -152,7 +152,7 @@ TEST(ExpressionArrayToObjectTest, KVFormatSimple) {
<< BSON("k"
<< "key2"
<< "v" << 3)))},
- {Value(BSON("key1" << 2 << "key2" << 3))}}});
+ Value(BSON("key1" << 2 << "key2" << 3))}});
}
TEST(ExpressionArrayToObjectTest, KVFormatWithDuplicates) {
@@ -163,19 +163,19 @@ TEST(ExpressionArrayToObjectTest, KVFormatWithDuplicates) {
<< BSON("k"
<< "hi"
<< "v" << 3)))},
- {Value(BSON("hi" << 3))}}});
+ Value(BSON("hi" << 3))}});
}
TEST(ExpressionArrayToObjectTest, ListFormatSimple) {
assertExpectedResults("$arrayToObject",
{{{Value(BSON_ARRAY(BSON_ARRAY("key1" << 2) << BSON_ARRAY("key2" << 3)))},
- {Value(BSON("key1" << 2 << "key2" << 3))}}});
+ Value(BSON("key1" << 2 << "key2" << 3))}});
}
TEST(ExpressionArrayToObjectTest, ListFormWithDuplicates) {
assertExpectedResults("$arrayToObject",
{{{Value(BSON_ARRAY(BSON_ARRAY("key1" << 2) << BSON_ARRAY("key1" << 3)))},
- {Value(BSON("key1" << 3))}}});
+ Value(BSON("key1" << 3))}});
}
/* ------------------------ ExpressionRange --------------------------- */
@@ -2103,7 +2103,7 @@ TEST(BuiltinRemoveVariableTest, RemoveSerializesCorrectlyAfterOptimization) {
namespace ExpressionMergeObjects {
TEST(ExpressionMergeObjects, MergingWithSingleObjectShouldLeaveUnchanged) {
- assertExpectedResults("$mergeObjects", {{{}, {Document({})}}});
+ assertExpectedResults("$mergeObjects", {{{}, Document({})}});
auto doc = Document({{"a", 1}, {"b", 1}});
assertExpectedResults("$mergeObjects", {{{doc}, doc}});