您可以使用以下命令查询 MongoDB 中所建的索引:

  1. 查询一个集合的所有索引:
db.collection.getIndexes()
  1. 查询一个指定的索引:
db.collection.getIndexes({'name': 'indexName'})
  1. 查询一个集合的索引数量:
db.collection.getIndexes().length
  1. 查询一个集合中的所有索引名称:
db.collection.getIndexes().forEach(function(index){print(index.name)})
  1. 查询一个集合中所有的复合索引:
db.collection.getIndexes().forEach(function(index){if(index.key.length > 1){print(index.name)}})
MongoDB 查询索引:完整指南及示例

原文地址: https://www.cveoy.top/t/topic/oBW4 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录