db.collection.getIndexes()

在本页面

Definition

  • db.collection. getIndexes ( )
    • 返回一个数组,该数组包含标识和描述集合中现有索引的文档列表。您必须在集合上致电db.collection.getIndexes()。例如:
db.collection.getIndexes()

collection更改为要为其返回索引信息的集合的名称。

Considerations

在 3.0.0 版中更改。

对于使用WiredTiger存储引擎的 MongoDB 3.0 部署,如果从 3.0 之前的mongo shell 版本或3 .0 兼容版本之前的驱动程序版本运行db.collection.getIndexes(),即使存在索引,db.collection.getIndexes()也不会返回任何数据。有关更多信息,请参见WiredTiger 和驱动程序版本兼容性

Required Access

执行该方法的用户需要system.indexes集合具有find特权或listIndexes特权操作。 read built-in role至少提供必要的权限。

Output

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