-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
What problem are you facing?
There are currently 3 ways to count documents:
- Collection.count(): has been deprecated for a while. Uses the db count command and behaves differently depending on the argument. It relies on collection metadata when no argument is passed or actually counts the documents matching the query when a query is passed
- Collection.countDocuments(): counts the documents with an aggregation
- Collection.estimatedDocumentCount(): relies on collection metadata to return an estimated count of the docs
mongosh offers the corresponding shell API to users, which is just a pass-through to the driver.
We recently discovered that at least in the most recent version of the driver, the semantics of Collection.count() has changed: it now always behaves like Collection.countDocuments(), which means that it might unexpectedly trigger a collection scan.
This unexpected behavior may cause performance degradations in production clusters as it's quite common for customers to have scripts for the legacy shell with calls to count() that are being ported to mongosh and that under the hood will behave very differently from what they expect.
We currently have about 17% of the 13k daily active users that use count() on a daily basis so we will want to fix this sooner rather than later.
What driver and relevant dependency versions are you using?
^4.3.0
Steps to reproduce?
Check what count() does.
- depends on
-
NODE-3879 Investigate NODE-3878 - Collection.count() should use the count db command
- Closed