【问题标题】:In MongoDB, is there anyway to tell what index is on a collection besides using coll.find({...}).explain()?在 MongoDB 中,除了使用 coll.find({...}).explain() 之外,还有什么方法可以告诉集合上的索引是什么?
【发布时间】:2010-09-21 01:17:44
【问题描述】:

我认为explain() 会告诉它可以使用的任何可能的索引。只显示集合上定义的所有索引怎么样? (甚至整个数据库?)

【问题讨论】:

    标签: indexing mongodb


    【解决方案1】:
    >db.system.indexes.find();
    
    >db.system.indexes.find( { ns: "tablename" } );
    

    会给你类似的东西

     { 
      "ns" : "test.fs.chunks", 
      "key" : { "files_id" : 1, "n" : 1 }, 
      "name" : "files_id_1_n_1" 
     }
    

    对于每个索引(ns 是集合名称)。

    【讨论】:

    • 看起来ns: 部分需要数据库名称和集合名称,例如foo.analytics
    【解决方案2】:

    或者使用集合名称。即,如果您有 users 集合,请执行以下操作:

    db.users.getIndexes()
    

    【讨论】:

      猜你喜欢
      • 2021-12-03
      • 1970-01-01
      • 2018-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-31
      • 1970-01-01
      • 1970-01-01
      • 2019-05-28
      相关资源
      最近更新 更多