What Is a Hashed Indexes in MongoDB?
Stores hashes of field values. Supports equality-style lookup and is commonly used for hashed shard keys; hash order is not value order.
How the Hashed Indexes Algorithm Works
Stores hashes of field values. Supports equality-style lookup and is commonly used for hashed shard keys; hash order is not value order.
When to Use Hashed Indexes
Equality-based routing and hashed sharding with an appropriate distribution.
How to Create a MongoDB Hashed Indexes
Review data quality, existing structures, feature support, build time, and deployment requirements before creating an index on a production table.
db.accounts.createIndex({ accountKey: "hashed" })Hashed Indexes Query Example
This example demonstrates the matching query shape. Check the execution plan to confirm that the engine can use the index.
db.accounts.find({ accountKey: "acct-104" })Queries Supported by Hashed Indexes
Equality-based routing and hashed sharding with an appropriate distribution. A similar-looking predicate may not use the same access path; operators, expressions, key order, and data type all matter.
Read Performance, Storage, and Write Costs
Cannot support range scans or ordered retrieval; hash distribution changes locality. Indexes reduce some search work but require storage and add maintenance to writes.
Hashed Indexes Limitations and Common Mistakes
Unique hashed indexes are unsupported; hash keys are not appropriate for range pagination.
Do not assume that an index being present means the optimizer chose it or that the query became selective.
How to Measure and Tune Hashed Indexes
Evaluate shard targeting, distribution, hotspot risk, and query explain output.
Compare representative plans and timings before and after, including concurrent writes and realistic data volumes.
Hashed Indexes Questions
Will the database always use this index?
No. The optimizer weighs selectivity, estimated costs, statistics, cache state, and the amount of data returned.
What should I verify before production?
Confirm version support, query compatibility, write overhead, build/rollback procedures, and index behavior during backup and recovery.
Official MongoDB Index Documentation
Check MongoDB documentation: Index Types for release-specific requirements and supported operators.