On this page本页内容
db.collection.
getIndexes
()¶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驱动程序文档。
Returns an array that holds a list of documents that identify and describe the existing indexes on the collection, including hidden indexes. 返回一个数组,其中包含一系列文档,这些文档标识并描述集合上的现有索引,包括隐藏索引。You must call 必须对集合调用db.collection.getIndexes()
on a collection. db.collection.getIndexes()
。For example:例如:
Change 将collection
to the name of the collection for which to return index information.collection
更改为要为其返回索引信息的集合的名称。
Starting in MongoDB 4.2, if the client that issued the 从MongoDB 4.2开始,如果发出db.collection.getIndexes()
disconnects before the operation completes, MongoDB marks the db.collection.getIndexes()
for termination (i.e. killOp
on the operation).db.collection.getIndexes()
的客户端在操作完成之前断开连接,MongoDB会将db.collection.getIndexes()
标记为终止(即操作上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
(恢复状态)。
To run 要在执行访问控制时运行db.collection.getIndexes()
when access control is enforced, usesrs must have privileges to listIndexes
on the collection.db.collection.getIndexes()
,UseSR必须具有在集合上listIndexes
的权限。
The built-in role 内置角色read
provides the required privileges to run db.collection.getIndexes()
for the collections in a database.read
提供为数据库中的集合运行db.collection.getIndexes()
所需的权限。
db.collection.getIndexes()
returns an array of documents that hold index information for the collection. 返回包含集合索引信息的文档数组。For example:例如:
Note
Starting in MongoDB 4.4, 从MongoDB 4.4开始,db.collection.getIndexes()
no longer includes the ns
field.db.collection.getIndexes()
不再包含ns
字段。
Index information includes the keys and options used to create the index. 索引信息包括用于创建索引的键和选项。The index option 从MongoDB 4.4开始提供的hidden
, available starting in MongoDB 4.4, is only available if the value is true
.index
选项hidden
仅在该值为true
时可用。
For information on the keys and index options, see 有关键和索引选项的信息,请参阅db.collection.createIndex()
.db.collection.createIndex()
。