On this page本页内容
db.collection.
unhideIndex
()¶mongo
Shell Method
This page documents the 本页记录了mongo
shell method, and does not refer to the MongoDB Node.js driver (or any other driver) method. mongo
shell方法,未提及MongoDB Node.js驱动程序(或任何其他驱动程序)方法。For corresponding MongoDB driver API, refer to your specific MongoDB driver documentation instead.有关相应的MongoDB驱动程序API,请参阅特定的MongoDB驱动程序文档。
Unhides an existing index from the query planner. 从查询计划器中取消隐藏现有索引。Once unhidden, the indexes are immediately available for use.一旦取消隐藏,这些索引立即可供使用。
The db.collection.unhideIndex()
method takes the following parameter:db.collection.unhideIndex()
方法采用以下参数:
index |
string or document |
Tip
|
The db.collection.unhideIndex()
is a mongo
shell wrapper for the collMod
command.db.collection.unhideIndex()
是collMod
命令的mongo
shell包装。
Unhiding a hidden index resets its 取消隐藏隐藏索引将重置其$indexStats
.$indexStats
。
Unhiding an already unhidden index has no effect on the index. 取消隐藏已取消隐藏的索引对该索引没有影响。However, the operation will still generate an empty oplog entry.但是,该操作仍将生成一个空的oplog条目。
If the deployment enforces authentication/authorization, you must have the 如果部署强制进行身份验证/授权,则必须在集合的数据库中拥有collMod
privilege in the collection’s database.collMod
权限。
The built-in role 内置角色dbAdmin
provides the required privileges.dbAdmin
提供所需的权限。
The following example unhides an existing index.以下示例取消隐藏现有索引。
First, use 首先,使用db.collection.createIndex()
to create a hidden index:db.collection.createIndex()
创建隐藏索引:
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
.index
选项为hidden
时,才会返回true
。
To unhide the index, you can specify either the index key specification document or the index name to the 要取消隐藏索引,可以指定索引键规范文档或db.collection.unhideIndex()
method. db.collection.unhideIndex()
方法的索引名。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
.hidden
不再作为borough_1_ratings_1
索引的一部分出现,因为该字段仅在值为true
时返回。