estimatedDocumentCount() (Estimate Document Count)

Last updated: 2026-10-09

estimatedDocumentCount() (Estimate Document Count)

estimatedDocumentCount() estimates the total document count from collection metadata, e.g. `db.users.estimatedDocumentCount()`. It takes no filter and scans nothing, so it is extremely fast, but the value can lag reality (especially on unflushed sharded clusters). It suits dashboards and capacity estimates where precision is not critical; for exact counts use countDocuments().

CategoryRead
MongoDB Version1.0+
Example Languagemongosh (Shell)

📝 Syntax

db.<collection>.estimatedDocumentCount()

Returns:Estimated total document count (integer).

▶ Example

Run the commands below in your local mongosh (requires a running mongod):

// estimatedDocumentCount: quickly check total users
const n = db.users.estimatedDocumentCount()
print('Total users (estimate): ' + n)

Output:

Total users (estimate): 1000

📌 Notes

📚 Related Tutorials

❓ FAQ

QWhy is estimatedDocumentCount faster than countDocuments?
AIt reads the count from collection metadata without scanning documents; countDocuments() actually evaluates the filter.
QIs estimatedDocumentCount accurate?
AUsually close, but not guaranteed; heavy writes or sharding can widen the gap.
QWhich count method should I pick?
AUse countDocuments() for exact or filtered counts; estimatedDocumentCount() when magnitude and speed matter.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏