Sparse indexes are incorrectly assigned to {$in: [null, ...]} predicates. As a consequence, {$in: [null, ...]} queries can omit documents from the result set that are missing the value of the given field, if a sparse index is assigned to the $in predicate.
Reproduce as follows:
> db.foo.drop() true > db.foo.ensureIndex({a: 1}, {sparse: true}) { "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } > db.foo.insert({}) WriteResult({ "nInserted" : 1 }) > db.foo.find({a: {$in: [null]}}) // No results: unexpected. > db.foo.find({a: {$in: [null]}}).hint({$natural: 1}) // 1 result: expected. { "_id" : ObjectId("55477a258aa4f4cc73af71a5") }
- links to