Priority: Major - P3
Affects Version/s: None
Fix Version/s: 100.3.0
The tools-common type db.DeferredQuery has a method EstimatedDocumentCount, but estimated counts are only possible on full collections, not on queries with filters.
As currently written, it will ignore the filter and return a full collection count, which is wrong.
I suggest the following changes:
- Run EstimatedDocumentCount on the underlying collection if the filter is nil or an empty BSON document
- Run CountDocuments on the underlying collection otherwise
- Consider renaming db.DeferredQuery.EstimatedDocumentCount to db.DeferredQuery.Count.