Distinct commands with no query predicate are incorrectly able to use a partial index, if the distinct field is the first element of the index key pattern. As a result, these distinct commands can miss results.
Reproduce as follows:
> db.foo.drop() true > db.foo.insert({a: 1, b: 1}) WriteResult({ "nInserted" : 1 }) > db.foo.distinct("a") [ 1 ] // expected > db.foo.ensureIndex({a: 1}, {partialFilterExpression: {b: 2}}) { "createdCollectionAutomatically" : false, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } > db.foo.distinct("a") [ ] // unexpected
- is related to
-
SERVER-17854 Allow $or predicates to be indexed by partial indexes
- Closed