$collStats (Collection Stats)
Last updated: 2026-10-09
$collStats (Collection Stats)
$collStats returns storage statistics for the collection — document count, data size, index info, and storage engine details — as a single document. Use it for capacity planning and growth monitoring. Select statistics via fields like latencyStats, storageStats, count, and queryExecStats. Values are approximate, not real-time exact.
| Category | Advanced & Diagnostic |
|---|---|
| MongoDB Version | 1.0+ |
| Example Language | mongosh (Shell) |
📝 Syntax
{ $collStats: { latencyStats: { histograms: <bool> }, storageStats: {}, count: {}, queryExecStats: {} } }
⚙️ Parameters
| storageStats | Returns storage statistics (documents, data and index sizes, etc.). |
|---|---|
| count | Returns document count statistics. |
| queryExecStats | Returns query execution statistics. |
| latencyStats | Returns latency statistics, optionally with histograms. |
Returns:A single document with collection statistics
▶ Example
Run the commands below in your local mongosh (requires a running mongod):
// $collStats: storage and count for the orders collection
db.orders.aggregate([
{ $collStats: { storageStats: {}, count: {} } }
])
Output:
// One document holding count and storageStats
📌 Notes
- Statistics are approximate, not real-time exact
- $indexStats covers only index usage; $collStats is broader
- Sharded collections return an aggregated view
🏷️ Related Tags
💡 Related Cases
More hands-on cases coming soon.
📚 Related Tutorials
❓ FAQ
QCan $collStats show index sizes?
AYes, storageStats includes totalIndexSize and per-index sizes.
QAre the values real-time?
ANo, some come from storage engine metadata and are approximate.
QHow does $collStats differ from db.stats?
Adb.stats is database-level; $collStats targets one collection and emits a structured document.