如何在MongoDB和PHP中对Map Reduce查询进行解释


How to use explain on a Map Reduce query in MongoDB and PHP

我使用explain做了一个简单的查询,以准确地知道执行时间。

    $this->db->toto->find($req)->sort(array('date' => 1))->explain();

我现在想用地图上的解释和减少查询,如何做到这一点?我应该使用"经典"分析系统吗?

我试图比较这两个查询的执行时间。

例如:

    $res = $this->db->command(array(
        "mapreduce" => "toto",
        "map" => $map,
        "reduce" => $reduce,
        "finalize" => $finalize,
        "query" => $req,
        "out" => array("inline"=>1)
    ))->explain();

不起作用,因为命令返回一个数组(解释需要一个MongoCursor)。

非常感谢:)

Explain在map/reduce这样的命令上不起作用。你可以做的就是对你正在使用的查询运行explain。

如果你只需要执行时间,你可以运行m/r并计时。这就是解释决定执行时间的方式。