estimatedDocumentCount()

Reference type:Cheat sheetFormat:Syntax + example + use case

Reference group: Collection CRUD methods

What it does

Returns a metadata-based estimate for the collection total.

Syntax

db.collection.estimatedDocumentCount()

Use case

Fast approximate total when no filter is needed.

estimatedDocumentCount(): practical example
db.orders.estimatedDocumentCount()
💡 Explanation Returns a metadata-based estimate for the collection total. When to use it Fast approximate total when no filter is needed.
Key Takeaways
  • Returns a metadata-based estimate for the collection total.
  • Typical use: Fast approximate total when no filter is needed.