15. Hashed, Wildcard, and Hidden Indexes
A hashed index stores hash values of indexed fields and can support equality-oriented access patterns, including some sharding strategies. Hashed indexes do not provide ordinary value ordering for range scans or sorting by the original values.
A wildcard index indexes fields across a document or a selected subdocument path. It can help when queryable fields are dynamic or not known in advance, but it is not automatically a replacement for carefully designed indexes on stable, high-volume query patterns.
A hidden index is maintained but hidden from the query planner. It can be useful for evaluating the effect of removing an index from planner consideration before actually dropping it. Hidden indexes still consume storage and maintenance resources.
These index types address specialized requirements. Choose them only when their trade-offs match the workload.
A hidden index is still stored and maintained on writes. Hiding it affects planner visibility, not its storage or maintenance cost.
// Equality-oriented hashed index.
db.users.createIndex({ externalId: "hashed" });
// Wildcard index for dynamic metadata fields.
db.events.createIndex({ "metadata.$**": 1 });
// Hide an existing index from query planning.
db.orders.hideIndex("status_1");
// Restore planner visibility later if needed.
db.orders.unhideIndex("status_1");- Hashed indexes are primarily suited to equality-oriented access patterns.
- Wildcard indexes can support dynamic field shapes.
- Hidden indexes let you test planner behavior without immediately dropping an index.
- Specialized indexes still have storage and write costs.
What happens when an index is hidden?