On this page本页内容
listIndexes
Returns information about the indexes on the specified collection, including hidden indexes. 返回有关指定集合的索引的信息,包括隐藏索引。Specifically, the command returns a document that contains information with which to create a cursor to the index information. 具体来说,该命令返回一个文档,该文档包含用于创建指向索引信息的游标的信息。Index information includes the keys and options used to create the index. 索引信息包括用于创建索引的键和选项。mongosh
provides the db.collection.getIndexes()
helper.mongosh
提供了db.collection.getIndexes()
帮助器。
The command has the following form:命令的格式如下:
{ "listIndexes": "<collection-name>" }
listIndexes | string | |
comment | any |
|
To run 要在实施访问控制时运行listIndexes
when access control is enforced, users must have privileges to listIndexes
. listIndexes
,用户必须具有listIndexes
的权限。The built-in role 内置的角色read
provides the required privileges to run listIndexes
for the collections in a database.read
提供了为数据库中的集合运行listIndexes
所需的权限。
Starting in MongoDB 4.2, if the client that issued the 从MongoDB 4.2开始,如果在操作完成之前发出listIndexes
disconnects before the operation completes, MongoDB marks the listIndexes
for termination (i.e. killOp
on the operation).listIndexes
的客户端断开连接,MongoDB会标记listIndexes
以终止(即操作上的killOp
)。
Starting in MongoDB 4.4, to run on a replica set member, 从MongoDB 4.4开始,要在副本集成员上运行,listIndexes
operations require the member to be in PRIMARY
or SECONDARY
state. listIndexes
操作要求成员处于PRIMARY
或SECONDARY
状态。If the member is in another state, such as 如果成员处于其他状态,如STARTUP2
, the operation errors.STARTUP2
,则操作将出错。
In previous versions, the operations can also be run when the member is in 在以前的版本中,也可以在成员处于STARTUP2
. STARTUP2
时运行操作。However, the operations wait until the member transitions to 但是,操作将等待成员转换到RECOVERING
.RECOVERING
。
listIndexes.cursor
A document that contains information with which to create a cursor to index information. 一种文档,包含用于创建游标以索引信息的信息。The cursor information includes the cursor id, the full namespace for the command, as well as the first batch of results. 游标信息包括游标id、命令的完整名称空间以及第一批结果。Index information includes the keys and options used to create the index. 索引信息包括用于创建索引的键和选项。The index option 索引选项hidden
, available starting in MongoDB 4.4, is only present if the value is true
.hidden
(从MongoDB 4.4开始可用)仅在值为true
时才存在。
For information on the keys and index options, see 有关键和索引选项的信息,请参阅db.collection.createIndex()
.db.collection.createIndex()
。