【问题标题】:How to check utility of indexes in mongo 2.4.14?如何检查 mongo 2.4.14 中索引的实用性?
【发布时间】:2017-10-24 13:16:52
【问题描述】:

我正在使用 php 和 2.4.14 版本的 mongodb。我需要减少索引来优化我的数据库。如何检查我需要哪些索引以及可以删除哪些索引?

【问题讨论】:

    标签: php mongodb mongodb-query


    【解决方案1】:

    其实你的问题还不清楚。 如果您尝试删除并获取结果中的特定索引。然后,按照下面的代码。

    $m = new MongoClient();
    $db = $m->dbName;
    $collection = $db->collectionName;
    
    $query = array();
    
    $fields = array(
            "_id" =>  FALSE, //if want to remove "_id" index pass false 
            "required_field" => TRUE //if you want "required_field" index pass true
    );
    $collection->find($query, $fields);
    

    【讨论】:

    • 我想检查我实际使用的索引,它是旧项目,我想减少索引的数量。
    【解决方案2】:

    按索引统计在 MongoDB 2.4.14 中不可用。但是,它在 MongoDB 3.2.0 及更高版本中作为聚合管道阶段可用:

    https://docs.mongodb.com/manual/reference/operator/aggregation/indexStats/

    请注意,MongoDB 2.4 系列已经很老了,目前不再支持。在撰写本文时,支持的最早的 MongoDB 版本是 3.0 系列。

    【讨论】:

    • 是的,我知道,但是明年我们将进入 3.2,我只需要提高数据库的速度几个月。
    猜你喜欢
    • 1970-01-01
    • 2023-01-19
    • 1970-01-01
    • 2017-03-14
    • 1970-01-01
    • 2018-07-17
    • 1970-01-01
    • 2013-07-22
    • 2021-10-03
    相关资源
    最近更新 更多