liveBook · Manning

Hidden index

As explained in MongoDB 8.0 in Action, Third Edition

A hidden index is a MongoDB index excluded from query-planner consideration while remaining maintained and enforceable like an unhidden index.

A hidden index stays maintained but is excluded from MongoDB’s query planner, letting you test the effect of removing it without permanently deleting it. section 7.4.4

Use hidden indexes as a reversible operational test:

  • Hide an existing index before dropping it from production. section 7.3 section 7.4.4
  • Observe application performance while queries run without planner access to the index. section 7.4.4
  • Unhide the index if performance degrades, avoiding index reconstruction. section 7.4.4
  • Account for continued maintenance: hidden indexes still enforce uniqueness, expire TTL documents, consume resources, and receive write updates. section 7.4.4
db.getSiblingDB('sample_mflix').movies.hideIndex(
    { runtime: 1 } // Specify the index key specification document
)

Hide the runtime index on sample_mflix.movies with mongosh by supplying its key specification document. section 7.4.4

db.collection.unhideIndex()
db.getSiblingDB('sample_mflix').movies.unhideIndex(
    { runtime: 1 } // Specify the index key specification document
)

Restore planner visibility with unhideIndex, or use the collMod command for the same management task. section 7.4.4

Testing a runtime index

Hide the runtime index on sample_mflix.movies and monitor user lookup performance. If lookups slow significantly, unhide the index to restore planner access. section 7.4.4

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Explains planner exclusion, reversible visibility, constraint enforcement, TTL behavior, resource consumption, and index-stat resets.
Examples
Demonstrates hiding the runtime index on sample_mflix.movies while observing user lookup performance.
What it assumes
Assumes an existing MongoDB index and familiarity with collection index-management commands.
What you can do after
Operate/configure index visibility with hideIndex, unhideIndex, or collMod while preserving a rollback path.
How it connects
Connects hidden indexes with query planners, unique indexes, TTL indexes, write operations, and index statistics.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of MongoDB 8.0 in Action, Third Edition. The section links point to the parts of the book it draws on.