Details
Description
The count command does not respect the user-specified hint, if an empty query predicate is specified.
This is due to a bug in CountStage::work(), which fails to check for a non-empty hint before deciding to apply the "trivial count" optimization.
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().hint({a: 1}).itcount()
|
0
|
> db.foo.find().hint({a: 1}).count()
|
1 // Unexpected: should return 0 instead. |
>
|