$indexStats (Index Stats)
Last updated: 2026-10-09
$indexStats (Index Stats)
$indexStats returns usage statistics per index — name, access count, misses, and last-use time — one document per index. Use it to find unused indexes or evaluate hit rates. Counters accumulate on the mongod instance and reset on restart; sharded collections report per shard.
| Category | Advanced & Diagnostic |
|---|---|
| MongoDB Version | 1.0+ |
| Example Language | mongosh (Shell) |
📝 Syntax
{ $indexStats: {} }
Returns:One statistics document per index
▶ Example
Run the commands below in your local mongosh (requires a running mongod):
// $indexStats: usage of each index on orders
db.orders.aggregate([
{ $indexStats: {} }
])
Output:
// One document per index with name, accesses, etc.
📌 Notes
- Counters accumulate from mongod start and reset on restart
- For index size and structure use $collStats instead
- Sharded collections emit one row per shard
🏷️ Related Tags
💡 Related Cases
Backup and Recovery, Security, and Operations
Indexing Fundamentals and Principles
Index Types and Advanced Features
📚 Related Tutorials
❓ FAQ
QCan $indexStats find unused indexes?
AYes, indexes with accesses of 0 that go unused for a long time are deletion candidates.
QDo the counters reset?
AYes, restarting mongod zeroes the counters.
QDoes $indexStats take parameters?
ANo, just use { $indexStats: {} }.