-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Querying
-
Query Optimization
-
Fully Compatible
-
ALL
-
v8.0, v7.3, v7.0, v6.0, v5.0
-
200
Bernard made a very insightful comment in a code review which lead us to realize this behavior:
db.c.drop(); db.c.insert({b: 1}); const query = {a: {$gte: null}}; // Returns the document. {b:1} printjson(db.c.find(query).toArray()); db.c.createIndex({a: 1}, {sparse: true}); // Returns nothing. printjson(db.c.find(query).toArray());
On a query like {a: {$gte: null}}, the planner may choose to use a sparse index on 'a', even though the results should include documents which don't have an 'a' field (and therefore, don't have a key in the sparse index).
I plan on fixing this as part of SERVER-36731, but we should probably do a special fix for older branches. [EDIT: We should decide which behavior is correct before changing anything].
- is duplicated by
-
SERVER-90476 Query using wildcard index can return incorrect results when comparing to null on non-existent field
- Closed
-
SERVER-90902 Query may give different results when filtering by $gte: MinKey() depending on the index used and not-existing/null value fields are involved
- Closed
- is related to
-
SERVER-44376 Indexed $gte/lte does not produce superset of results returned by $eq for 'undefined' values
- Closed