使用
db.collection.getIndexes()方法可以查看MongoDB中集合的索引。
在MongoDB中,可以使用以下方法来查看索引:
1、使用db.collection.getIndexes()命令:

db表示数据库名称。
collection表示集合名称。
getIndexes()是用于获取集合的索引信息的命令。
示例代码:
```javascript
db.myCollection.getIndexes()
```

2、使用db.collection.findIndexes()命令:
db表示数据库名称。
collection表示集合名称。
findIndexes()是用于查找集合的索引信息的命令。
示例代码:
```javascript
db.myCollection.findIndexes()

```
3、使用MongoDB Compass工具:
MongoDB Compass是一个可视化工具,可以方便地查看和管理MongoDB数据库和集合的索引信息。
打开MongoDB Compass并连接到相应的数据库。
选择要查看索引的集合。
在集合的导航面板中,点击"Indexes"选项卡即可查看索引信息。
4、使用MongoDB Shell命令行界面:
打开MongoDB Shell并连接到相应的数据库。
使用show indexes命令查看集合的索引信息。
示例代码:
```shell
show indexes myCollection
```