Per-node and per-shard $indexStats aggregation across replica sets and shards
Parent: Unused index detection with $indexStats · Published reference · snapshot 2026-10-30
↓ Facts as markdownall context files
Source-anchored research for Per-node and per-shard $indexStats aggregation across replica sets and shards. Run status: COMPLETED.
These notes link each claim to its source. Some citations identify archived research reports that are no longer hosted on this site. A published reference means the content is available; it does not certify independent review or accuracy.Read the editorial policy and follow the sources before relying on a claim.
Definitions
- A zero count is a candidate-review signal, not sufficient grounds for dropping an index. Review all members and workloads that run infrequently; a short observation window can miss necessary usage. (high confidence) [source]
How it works
- Results identify the mongod host and, for sharded deployments, the shard. Keep both identities when collecting per-index measurements. (high confidence) [source]
- Index counters reset on mongod restart, index drop/recreation, or modification with collMod. Preserve accesses.since when comparing samples; raw cumulative counts from different observation windows are not directly comparable. (high confidence) [source]
- Methodological inference: collect per-host samples before grouping by shard and index; compare intervals only when counter epochs match. A shard rollup otherwise hides unsampled members or differing observation windows. (medium confidence) [source]
How-to and procedures
- Run db.collection.aggregate([{ $indexStats: {} }]). The stage must come first and takes an empty document. Rows include index name and key, originating host, accesses.ops and accesses.since; sharded output also identifies the shard. (high confidence) [source]
Problems, failure modes and limitations
- Studio 3T demonstrates separate purposes: explain displays a particular query’s index use and document retrieval, whereas $indexStats reports usage frequency. Usage counts alone cannot establish query coverage. (low confidence) [source]
- An OpenTelemetry receiver issue reported direct shard-member monitoring still issuing IndexStats despite disabled database metrics, using Splunk Collector 0.127.0. This is a version-specific monitoring caveat, not proof of current behavior. (low confidence) (verified as of 2026-02-06) [source]
Comparisons and alternatives
- Percona PMM documents that its unused-index advisor requires the indexStats metric collector. Missing advisor evidence can therefore reflect collection configuration rather than an absence of index usage. (low confidence) [source]
Facts and statements
- $indexStats accesses counters are local to the node executing the query. Usage on a secondary is not recorded on the primary or other members; inspect every relevant replica-set member before declaring an index unused. (high confidence) [source]
- MongoDB issue SERVER-96438, updated October 12, 2026 and recorded as unresolved, describes mongos collecting results across shard primaries while omitting secondaries. Its request for all-node results is proposed behavior, not evidence that the feature exists. (low confidence) (verified as of 2026-10-12) [source]
- accesses.ops counts user operations using an index; TTL deletions and chunk split or migration activity are excluded. It is not a count of indexed documents. (low confidence) [source]
- Methodological inference: retain collection namespace, index specification, shard and host before rolling up counters. Collect nodes explicitly; summing mongos-returned rows alone must not be presented as all-member coverage. (medium confidence) [source]
- Methodological inference for covered-query analysis: index-use counters alone do not establish query coverage. Pair them with explain executionStats to inspect the actual index and document-scanning behavior of the specific query. (medium confidence) [source]
- Historical counterexample: a MongoDB 3.2.11 incident report describes worse performance after dropping zero-counter indexes. The issue was closed as a duplicate of a checkpoint-related drop issue; it does not establish that current indexStats counters are defective. (low confidence) [source]
Children
- No children recorded.