estimatedDocumentCount() – Returns the count of all documents in a collection

Finds the number of documents, or the number of rows, in a collection.

Syntax diagram

Read syntax diagramSkip visual syntax diagramdb.collection. estimatedDocumentCount()

Command parameters

query
No query requires.

Examples

The following example shows the command syntax for returning the count of all documents in the collection, comments:
db.comments.estimatedDocumentCount()
The following example shows the successful output from running the estimatedDocumentCount command:
56