<!-- llms-explorer concept facts · https://llms-explorer.com/tree/hashed-and-compound-hashed-shard-keys-and-index-coverage/ · pack 2026-10-23 · ~718 tokens -->

# Hashed and compound hashed shard keys and index coverage

> Source-anchored research for Hashed and compound hashed shard keys and index coverage. Run status: COMPLETED.

Parent: [Covered queries on sharded collections](https://llms-explorer.com/tree/covered-queries-on-sharded-collections/) · 3 facets · 6 facts · page: https://llms-explorer.com/tree/hashed-and-compound-hashed-shard-keys-and-index-coverage/

## 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](https://www.mongodb.com/docs/manual/core/query-optimization/)

## 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](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-hashed/)
- 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](https://www.mongodb.com/docs/manual/core/hashed-sharding/)
- 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](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-hashed/)

## 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](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-hashed/create.md)
- 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](https://www.mongodb.com/docs/manual/core/hashed-sharding/)
