title: Group documents by month in MongoDB
body: <p>Right now I have a Mongoose query which looks something like</p>
  
  <pre><code>Collection
    .find( selector )
    .sort( sortCriteria )
    .select( selectCriteria )
    .populate( populateCriteria1 )
    .populate( populateCriteria2 )
    .then( docs =&gt; ... )
    .catch( errHandler )
  </code></pre>
  
  <p>So I am doing quite a lot in my query.</p>
  
  <p>Each document in my collection has a date. I want the documents returned grouped by month and year. So it should become something like</p>
  
  <pre><code>docs = [
    { _id: { year: 2017, month: 4 }, docs: [ ... ] },
    { _id: { year: 2017, month: 5 }, docs: [ ... ] },
    { _id: { year: 2017, month: 6 }, docs: [ ... ] }
  ]
  </code></pre>
  
  <p>I guess this is a simple <code>.aggregate()</code>, but I am not sure where I should include it since I am doing filtering using <code>.find()</code>, sorting using <code>.sort()</code>, field selection using <code>.select()</code>, and populates using <code>.populate()</code>.</p>
  
  <p>Each document has the field <code>date</code>, so it might be something like</p>
  
  <pre><code>Collection
    .find( selector )
    .aggregate([
      { $project: { month: { $month: $date }, year: { $year },
      { $group: { _id: { $month: $date, $year: $date }, docs: { $push: '' } }
    ])
  </code></pre>