MongoCollection#count API has been deprecated in Mongo Driver 3.8 in favor of:
Current count implementation is superseded by the estimatedDocumentCount implementation and leverages collection metadata to count documents.
New countDocuments executes an aggregation of documents to count them. The new API is more accurate as collection metadata can be refreshed asynchronously.
From MongoDB documentation:
Unlike db.collection.count(), db.collection.countDocuments() does not use the metadata to return the count. Instead, it performs an aggregation of the document to return an accurate count, even after an unclean shutdown or in the presence of orphaned documents in a sharded cluster.
In some cases we can observe that the returned count is not enough accurate for our needs, this is the case on MongoDB directories in the drop and create vocabulary scenario detailed below:
- drop the collection
- executes a count filtered by entity id to create
- create entity if count is 0 otherwise throw an error
We want to review all of our usage of count API in Nuxeo Platform and choose the correct new API.
So for these two LTS, we need to check if we can use countDocuments by checking the MongoDB server version or with a configuration parameters on nuxeo side.. As it, we can provide accurate count for compatible setup.