title: MongoDB Aggregation: How to get total records count?
body: <p>I have used aggregation for fetching records from mongodb.</p>
  
  <pre><code>$result = $collection-&gt;aggregate(array(
    array('$match' =&gt; $document),
    array('$group' =&gt; array('_id' =&gt; '$book_id', 'date' =&gt; array('$max' =&gt; '$book_viewed'),  'views' =&gt; array('$sum' =&gt; 1))),
    array('$sort' =&gt; $sort),
    array('$skip' =&gt; $skip),
    array('$limit' =&gt; $limit),
  ));
  </code></pre>
  
  <p>If I execute this query without limit then 10 records will be fetched. But I want to keep limit as 2. So I would like to get the total records count. How can I do with aggregation? Please advice me. Thanks</p>