title: MongoDB connector for PHP: count documents for pagination
body: <p>I'm using the <code>MongoDB\Driver\Manager</code> to connect to MongoDB using PHP. The driver version is 1.6.14 and I can connect and make a query. </p>
  
  <p>But I need the total number of documents for my query to make the pagination:</p>
  
  <pre><code>$reg_pag = 20;
  $pag = $_GET["pag"];
  
  $mng = new MongoDB\Driver\Manager("mongodb://localhost:27017");
  $filter = [];
  $filter["brand"] = $_GET["brand"];
  $options = ["skip" =&gt; ($pag-1)*$reg_pag , "limit" =&gt; $reg_pag];
  $query = new MongoDB\Driver\Query($filter, $options);
  $rows = $mng-&gt;executeQuery("carsdb.cars", $query);
  </code></pre>
  
  <p>I try with <code>$rows-&gt;count()</code> and with <code>count($rows)</code>. The first command doesn't work and the last command returns the filtered data (return 20).</p>