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
