summaryrefslogtreecommitdiff
path: root/src/mongo/db/matcher/expression_leaf_test.cpp
diff options
context:
space:
mode:
authorDavid Storch <david.storch@mongodb.com>2021-06-01 18:14:41 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-06-14 15:25:21 +0000
commitd75f3a8bb66ef1ef41bfd16eecd42c31f91c818b (patch)
tree1dbfaf604282e43d5fcf2d6a3e67f9eeaa254cdb /src/mongo/db/matcher/expression_leaf_test.cpp
parenta2d174f0aa4c9cbac4b39863d0f6c37f4774470b (diff)
downloadmongo-d75f3a8bb66ef1ef41bfd16eecd42c31f91c818b.tar.gz
SERVER-21929 Make $in with null always match undefined
Diffstat (limited to 'src/mongo/db/matcher/expression_leaf_test.cpp')
-rw-r--r--src/mongo/db/matcher/expression_leaf_test.cpp26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/mongo/db/matcher/expression_leaf_test.cpp b/src/mongo/db/matcher/expression_leaf_test.cpp
index 8ee1d50cb1b..209a6b80225 100644
--- a/src/mongo/db/matcher/expression_leaf_test.cpp
+++ b/src/mongo/db/matcher/expression_leaf_test.cpp
@@ -134,11 +134,14 @@ TEST(EqOp, MatchesReferencedArrayValue) {
TEST(EqOp, MatchesNull) {
BSONObj operand = BSON("a" << BSONNULL);
EqualityMatchExpression eq("a", operand["a"]);
- ASSERT(eq.matchesBSON(BSONObj(), nullptr));
- ASSERT(eq.matchesBSON(BSON("a" << BSONNULL), nullptr));
- ASSERT(!eq.matchesBSON(BSON("a" << 4), nullptr));
- // A non-existent field is treated same way as an empty bson object
- ASSERT(eq.matchesBSON(BSON("b" << 4), nullptr));
+ ASSERT_TRUE(eq.matchesBSON(BSONObj(), nullptr));
+ ASSERT_TRUE(eq.matchesBSON(BSON("a" << BSONNULL), nullptr));
+ ASSERT_FALSE(eq.matchesBSON(BSON("a" << 4), nullptr));
+
+ // {$eq:null} has special semantics which say that both missing and undefined match, in addition
+ // to literal nulls.
+ ASSERT_TRUE(eq.matchesBSON(BSON("b" << 4), nullptr));
+ ASSERT_TRUE(eq.matchesBSON(BSON("a" << BSONUndefined), nullptr));
}
// This test documents how the matcher currently works,
@@ -1192,11 +1195,14 @@ TEST(InMatchExpression, MatchesNull) {
std::vector<BSONElement> equalities{operand.firstElement()};
ASSERT_OK(in.setEqualities(std::move(equalities)));
- ASSERT(in.matchesBSON(BSONObj(), nullptr));
- ASSERT(in.matchesBSON(BSON("a" << BSONNULL), nullptr));
- ASSERT(!in.matchesBSON(BSON("a" << 4), nullptr));
- // A non-existent field is treated same way as an empty bson object
- ASSERT(in.matchesBSON(BSON("b" << 4), nullptr));
+ ASSERT_TRUE(in.matchesBSON(BSONObj(), nullptr));
+ ASSERT_TRUE(in.matchesBSON(BSON("a" << BSONNULL), nullptr));
+ ASSERT_FALSE(in.matchesBSON(BSON("a" << 4), nullptr));
+
+ // When null appears inside an $in, it has the same special semantics as an {$eq:null}
+ // predicate. In particular, we expect it to match both missing and undefined.
+ ASSERT_TRUE(in.matchesBSON(BSON("b" << 4), nullptr));
+ ASSERT_TRUE(in.matchesBSON(BSON("a" << BSONUndefined), nullptr));
}
TEST(InMatchExpression, MatchesUndefined) {