MongoDB 查询索引:完整指南及示例
您可以使用以下命令查询 MongoDB 中所建的索引:
- 查询一个集合的所有索引:
db.collection.getIndexes()
- 查询一个指定的索引:
db.collection.getIndexes({'name': 'indexName'})
- 查询一个集合的索引数量:
db.collection.getIndexes().length
- 查询一个集合中的所有索引名称:
db.collection.getIndexes().forEach(function(index){print(index.name)})
- 查询一个集合中所有的复合索引:
db.collection.getIndexes().forEach(function(index){if(index.key.length > 1){print(index.name)}})
原文地址: https://www.cveoy.top/t/topic/oBW4 著作权归作者所有。请勿转载和采集!