title: MongoDB group by type and by date
body: <p>I have a Collection with a simple Document to store <code>impressions</code> and <code>conversions</code> with the following structure:</p>
  
  <pre><code>/* 1 */
  {
      "_id" : ObjectId("566f1ef857c1e6dd3123050a"),
      "path_id" : ObjectId("55944c1ebe244fd19cbf510b"),
      "data_type" : "impression",
      "created_at" : ISODate("2015-12-14T19:56:40.100Z"),
      "__v" : 0
  }
  
  /* 2 */
  {
      "_id" : ObjectId("566f1fc9ac964e6f327c55d6"),
      "path_id" : ObjectId("55944c1ebe244fd19cbf510b"),
      "data_type" : "conversion",
      "created_at" : ISODate("2015-12-14T20:00:09.972Z"),
      "__v" : 0
  }
  
  /* 3 */
  {
      "_id" : ObjectId("566f2896739f6afa4485f327"),
      "path_id" : ObjectId("562e594315ef3d8c3f05d219"),
      "data_type" : "impression",
      "created_at" : ISODate("2015-12-14T20:37:42.139Z"),
      "__v" : 0
  }
  
  /* 4 */
  {
      "_id" : ObjectId("566f28e5739f6afa4485f328"),
      "path_id" : ObjectId("562e594315ef3d8c3f05d219"),
      "data_type" : "impression",
      "created_at" : ISODate("2015-12-14T20:39:01.233Z"),
      "__v" : 0
  }
  </code></pre>
  
  <p>I'm able to group and count by <code>data_type</code>, but what I need to do is group by <code>date</code> and then count the <code>data_type</code> in order to get the following result:</p>
  
  <pre><code>[
      {
          '_id': 'Y',
          'conversions': 20,
          'impressions': 2703,
          'date': '2015-12-14'
      },
      {
          '_id': 'Z',
          'conversions': 10,
          'impressions': 1703,
          'date': '2015-12-13'
      } 
  ]
  </code></pre>
  
  <p>The code I have right now is the following, but it only groups by <code>data_type</code>. I'm trying to add a project to regroup by date with no luck so far.</p>
  
  <pre><code>var path_id = new mongoose.Types.ObjectId( req.body.path_id );
  var match = {
      'path_id': {
          $eq: path_id
      }
  };
  
  var group = {
      '_id': '$data_type',
      'count': {
          '$sum': 1
      }
  }
  
  Hit.aggregate( [ {
      $match: match
  }, {
      $group: group
  } ], function( err, res ) {
      console.log( res );
  } );
  </code></pre>
  
  <p>The result is</p>
  
  <pre><code>POST /api/hits/bypath 200 30ms - 15b
  [ { _id: 'conversion', count: 2 },
    { _id: 'impression', count: 2703 } ]
  </code></pre>