mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-24 00:17:37 +01:00
2c808c0fd7
[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
29 lines
715 B
JavaScript
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);
|
|
}
|