Hashed and compound hashed shard keys and index coverage
Parent: Covered queries on sharded collections · Published reference · snapshot 2026-10-23 · skill mongodb-cohort-74cd39f19180
↓ Facts as markdownall context files
Source-anchored research for Hashed and compound hashed shard keys and index coverage. 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.
Structure and components
- MongoDB's covered-query requirements say a single index must contain every query field, fields needed internally for sharding, and every returned field; on mongos, the index must contain the shard key. A general compound-index guide also notes that _id must be indexed or excluded from the projection. (high confidence) [source]
Problems, failure modes and limitations
- MongoDB's hashed-index manual says hashed indexes cannot cover a query. Its server test shows that find({_id: true}, {_id: 0}) against a collection sharded by {_id: "hashed"} still has totalDocsExamined: 1, so the hashed shard-key value is not returned from the index alone. (high confidence) (verified as of 2026-10-20) [source]
- With a single-field hashed shard key, equality matches can target one shard; hashing preserves distribution for monotonically changing values but removes original-value range locality, so a range predicate cannot use the hashed index and may broadcast to multiple shards. (high confidence) (verified as of 2026-08-04) [source]
- Inference for compound hashed shard keys: MongoDB defines the compound form as an index with one hashed key and other ordinary ordered keys, while its index-type manual says hashed indexes cannot cover queries. The compound hashed index should therefore be treated as non-covering even when ordinary fields match the query and projection. The cited server test directly checks only a single-field hashed shard key, not this compound case. (medium confidence) (verified as of 2026-10-20) [source]
Facts and statements
- A compound hashed index hashes one field only and stores its other fields with ascending or descending order; the hashed field can be combined with ordinary fields before or after it. (high confidence) [source]
- A non-hashed prefix in a compound hashed shard key can define zone ranges while the hashed field distributes values more evenly; this combination does not make the compound hashed index cover queries. (high confidence) [source]
Children
- No children recorded.