title: How to use explain on a Map Reduce query in MongoDB and PHP
body: <p>I was doing a simple query using explain to know precisely the execution time.</p>
  
  <pre><code>    $this-&gt;db-&gt;toto-&gt;find($req)-&gt;sort(array('date' =&gt; 1))-&gt;explain();
  </code></pre>
  
  <p>I now want to use explain on a map and reduce query, how to do that ?
  Should I use the 'classic' profiling system?</p>
  
  <p>I'm trying to compare the execution time of theses 2 queries.</p>
  
  <p>ex:</p>
  
  <pre><code>    $res = $this-&gt;db-&gt;command(array(
          "mapreduce" =&gt; "toto",
          "map" =&gt; $map,
          "reduce" =&gt; $reduce,
          "finalize" =&gt; $finalize,
          "query" =&gt; $req,
          "out" =&gt; array("inline"=&gt;1)
      ))-&gt;explain();
  </code></pre>
  
  <p>Doesn't work because command return an array (explain need a MongoCursor).</p>
  
  <p>Thanks you a lot :)</p>