summaryrefslogtreecommitdiff
path: root/src/mongo/db/index
diff options
context:
space:
mode:
authorJustin Seyster <justin.seyster@mongodb.com>2019-10-28 22:57:03 +0000
committerevergreen <evergreen@mongodb.com>2019-10-28 22:57:03 +0000
commit53d3aae5f8e998e6a6625c9e99da8616640d3ba6 (patch)
tree88cd6c2576f4854179d1d737ce03052902f0f379 /src/mongo/db/index
parentfe7c6ee421ec900adcc7b90e79ddc9564c481605 (diff)
downloadmongo-53d3aae5f8e998e6a6625c9e99da8616640d3ba6.tar.gz
SERVER-42565 Agg and find commands sort missing fields differently
The problem described by this ticket was fixed as part of work in an earlier commit on master (0b80f48b). This commit adds testing to verify the fix.
Diffstat (limited to 'src/mongo/db/index')
-rw-r--r--src/mongo/db/index/sort_key_generator_test.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/mongo/db/index/sort_key_generator_test.cpp b/src/mongo/db/index/sort_key_generator_test.cpp
index 29ca2039153..59991cf4947 100644
--- a/src/mongo/db/index/sort_key_generator_test.cpp
+++ b/src/mongo/db/index/sort_key_generator_test.cpp
@@ -137,6 +137,38 @@ TEST(SortKeyGeneratorTest, SortKeyGenerationForArraysRespectsCompoundOrdering) {
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}}});
+ 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}}});
+ 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}}}}}});
+ 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{}}}}}});
+ 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}}});
+ ASSERT_VALUE_EQ(sortKey, Value{BSONNULL});
+}
+
TEST(SortKeyGeneratorTest, SortPatternComponentWithStringUasserts) {
ASSERT_THROWS_CODE_AND_WHAT(makeSortKeyGen(BSON("a"
<< "foo"),