# db.collection.getIndexes()

在本页面

* [定义](#definition)
* [行为](#behavior)
* [必需的访问权](#required-access)
* [输出](#output)

## 定义

* `db.collection.` `getIndexes` ()

返回一个 array，其中包含用于标识和描述集合上现有索引的文档列表。您必须在集合上调用db.collection.getIndexes()。例如：

```
db.collection.getIndexes()
```

将`collection`更改为要为其返回索引信息的集合的 name。

## 行为

从MongoDB 4.2开始，如果发出`db.collection.getIndexes()`断开连接的客户端在操作完成之前断开连接，则MongoDB将标记`db.collection.getIndexes()`为终止（即`killOp`在操作上）。

## 必需的访问权

要`db.collection.getIndexes()`在强制执行访问控制时运行，使用者必须`listIndexes`对该集合具有访问权限。

内置角色`read`提供了`db.collection.getIndexes()`为数据库中的集合运行所需的特权。

## 输出

db.collection.getIndexes()返回包含集合索引信息的 array 文档。索引信息包括用于创建索引的键和选项。有关键和索引选项的信息，请参阅db.collection.createIndex()。

译者：李冠飞

校对：


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mongoing.com/can-kao/mongo-shell-methods/collection-methods/db-collection-getindexes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
