listIndexes

On this page本页内容

Definition定义

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>" }
Field字段Type类型Description描述
listIndexesstringThe name of the collection.集合的名称。
commentany

Optional. 可选。A user-provided comment to attach to this command. 用户提供了附加到此命令的注释。Once set, this comment appears alongside records of this command in the following locations:设置后,此注释将与此命令的记录一起显示在以下位置:

A comment can be any valid BSON type(string, integer, object, array, etc).注释可以是任何有效的BSON类型(字符串、整数、对象、数组等)。

New in version 4.4.在版本4.4中新增

Required Access所需访问权限

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所需的权限。

Behavior行为

Client Disconnection客户端断开连接

Starting in MongoDB 4.2, if the client that issued the listIndexes disconnects before the operation completes, MongoDB marks the listIndexes for termination (i.e. killOp on the operation).从MongoDB 4.2开始,如果在操作完成之前发出listIndexes的客户端断开连接,MongoDB会标记listIndexes以终止(即操作上的killOp)。

Replica Set Member State Restriction副本集成员状态限制

Starting in MongoDB 4.4, to run on a replica set member, listIndexes operations require the member to be in PRIMARY or SECONDARY state. 从MongoDB 4.4开始,要在副本集成员上运行,listIndexes操作要求成员处于PRIMARYSECONDARY状态。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

Output输出

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()

listIndexes.ok

The return value for the command. 命令的返回值。A value of 1 indicates success.1表示成功。

←  listDatabaseslogRotate →