Does running count() incur a read for the documents counted?

Hello @Travis_Aucoin, welcome to the MongoDB Community forum!

MongoDB NodeJS Driver API has three Collection class methods related with counting documents:

countDocuments: Gets the number of documents matching the filter. This gets the accurate count.

For a fast count of the total documents in a collection see estimatedDocumentCount: Gets an estimate of the count of documents in a collection using collection metadata.

count: An estimated count of matching documents in the db to a filter. NOTE: This method has been deprecated, since it does not provide an accurate count of the documents in a collection. To obtain an accurate count of documents in the collection, use countDocuments. To obtain an estimated count of all documents in the collection, use estimatedDocumentCount.

There is also a FindCursor#count: Get the count of documents for this cursor. This method is deprecated. Use collection.estimatedDocumentCount or collection.countDocuments instead.


Related References:

1 Like