On a largeish collection, results from count() applied to a query appear to return the number of scanned objects instead of the number of objects returned by the find():
db.activity.findOne(
{'datacache.user.id': null})
null
> db.activity.find(
{'datacache.user.id': null})
(No result)
> db.activity.find(
{'datacache.user.id': null}).count()
816
> db.activity.count(
{'datacache.user.id': null})
816
> db.activity.find(
{'datacache.user.id': null}).explain()
{
"cursor" : "BtreeCursor datacache_user_id_1",
"nscanned" : 816,
"nscannedObjects" : 816,
"n" : 0,
"millis" : 44,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : true,
"indexOnly" : false,
"indexBounds" :
}
Searching for values besides null in that collection is inconclusive: result count always matches scanned count in such cases, they only differ for null.
- duplicates
-
SERVER-4529 fast count mode should not be used when matching against null
- Closed
- is related to
-
SERVER-4493 v0 indexes store empty arrays as nulls and the documents containing them may be improperly returned or counted when the matcher is bypassed
- Closed