- Reference >
mongo
Shell Methods >- Collection Methods >
- db.collection.unhideIndex()
db.collection.unhideIndex()¶
On this page
Definition¶
-
db.collection.
unhideIndex
()¶ mongo
Shell MethodThis page documents the
mongo
shell method, and does not refer to the MongoDB Node.js driver (or any other driver) method. For corresponding MongoDB driver API, refer to your specific MongoDB driver documentation instead.Unhides an existing index from the query planner. Once unhidden, the indexes are immediately available for use.
Syntax¶
Parameters¶
The db.collection.unhideIndex()
method takes the following
parameter:
Parameter | Type | Description |
---|---|---|
index |
string or document | Specifies the index to unhide from the query planner. You can specify the index either by the index name or by the index specification document. Tip You can use the To unhide a text index, specify the index name. |
The db.collection.unhideIndex()
is a mongo
shell
wrapper for the collMod
command.
Behavior¶
Index Modifications Reset Statistics¶
Unhiding a hidden index resets its $indexStats
.
No-op¶
Unhiding an already unhidden index has no effect on the index. However, the operation will still generate an empty oplog entry.
Required Access¶
If the deployment enforces authentication/authorization, you must have
the collMod
privilege in the collection’s database.
The built-in role dbAdmin
provides the required privileges.
Example¶
The following example unhides an existing index.
First, use db.collection.createIndex()
to create a hidden
index:
To verify, run db.collection.getIndexes()
on the
restaurants
collection:
The operation returns the following information:
The index option hidden
is only returned if the value is true
.
To unhide the index, you can specify either the index key specification
document or the index name to the db.collection.unhideIndex()
method. The following specifies the index name:
To verify, run db.collection.getIndexes()
on the
restaurants
collection:
The operation returns the following information:
The index option hidden
no longer appears as part of the
borough_1_ratings_1
index since the field is only returned if the
value is true
.