0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-24 00:17:37 +01:00
mongodb/jstests/query_golden/eq.js
HanaPearlman 2c808c0fd7 SERVER-81378: Make comparison to null via MatchExpression $eq and $in not match undefined (#19523)
[SERVER-81378](https://jira.mongodb.org/browse/SERVER-81378): Make
comparison to null via MatchExpression $eq and $in not match undefined.

Previously, queries like {a: {$eq: null}} matched documents including,
among others, {a: null} and {a: undefined}. This change makes it so that
comparison to null via MatchExpression $eq and $in does not match
documents like the latter. By extension, classic $lookup behavior is
also changed so that null local fields do not match undefined foreign
fields (this was already the case for $lookup executed in SBE). This
commit does not affect the behavior of agg expressions, which have their
own, different semantics for undefined values.

As a result of this change, index scan plans for comparison to null
queries can look different. For example, query {a: {$eq: null}} using
index {a: 1} will only have index bounds for the null interval, rather
than both the null and undefined intervals.

GitOrigin-RevId: 496fd240a87e96bb9a46db9be2610335a002d283
2024-03-05 23:02:49 +00:00

29 lines
715 B
JavaScript

/**
* Tests $eq against a variety of BSON types and shapes.
*/
import {show} from "jstests/libs/golden_test.js";
import {leafs, smallDocs} from "jstests/query_golden/libs/example_data.js";
const docs = smallDocs();
const coll = db.query_golden_eq;
coll.drop();
let output = '';
jsTestLog('Inserting docs:');
show(docs);
coll.insert(docs);
print(`Collection count: ${coll.find().itcount()}`);
for (const leaf of leafs()) {
// Direct comparisons against undefined ({$eq: undefined}) are not allowed.
if (tojson(leaf).match(/undefined/))
continue;
const query = coll.find({a: {$eq: leaf}}, {_id: 0});
jsTestLog(`Query: ${tojsononeline(query._convertToCommand())}`);
show(query);
}