-
Type: Task
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 5.0.26, 6.0.15, 7.0.9
-
Component/s: None
-
None
-
Query Execution
Example:
db.foo.insertMany([ { _id: 1, a: 1}, { _id: 2, a: null}, { _id: 3, b:1 } ]) db.foo.createIndex({"a":1}) db.foo.aggregate([{$match: { "a": {$gte: MinKey()}}}, {$group: {_id: "$a", c: {$sum:1}}}]) [ { _id: null, c: 2 }, { _id: 1, c: 1 } ] db.foo.dropIndexes() db.foo.createIndex({ "$**": 1 }) db.foo.aggregate([{$match: { "a": {$gte: MinKey()}}}, {$group: {_id: "$a", c: {$sum:1}}}]) [ { _id: null, c: 1 }, { _id: 1, c: 1 } ]
When using classic index filtering by $gte: MinKey() takes into account not existing fields and null value (and therefore the query can be even covered) having { _id: null, c: 2 }
When using wildcard indexes only the null values are taken into account and not the not-existing fields, therefore the query result is different compared to using classic index { _id: null, c: 1 } and the query cannot be covered.
- duplicates
-
SERVER-37164 Incorrect query results on $gte null with sparse index
- Closed