mongodb查询所建的索引
可以通过以下命令查询MongoDB中所建的索引:
- 查询一个集合的所有索引:
db.collection.getIndexes()
- 查询一个指定的索引:
db.collection.getIndexes({"name": "indexName"})
- 查询一个集合的索引数量:
db.collection.getIndexs().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/g8Wk 著作权归作者所有。请勿转载和采集!