title: Sum the different grades by date in MongoDB
body: <p>I'm using the restaurants dataset from the MongoDB website.  A document has arrays like the following:</p>
  
  <pre><code>{
      "grades" : [ 
          {
              "date" : ISODate("2014-06-10T00:00:00.000Z"),
              "grade" : "A"
          }, 
          {
              "date" : ISODate("2013-06-05T00:00:00.000Z"),
              "grade" : "B",
              "score" : 7
          }, 
          {
              "date" : ISODate("2012-04-13T00:00:00.000Z"),
              "grade" : "A"
          }, 
          {
              "date" : ISODate("2011-10-12T00:00:00.000Z"),
              "grade" : "A"
          }
      ]
  }
  </code></pre>
  
  <p>I'm trying to get a list of all dates, with a count of how many of each grade there was on that day.</p>
  
  <p>I've got this far:</p>
  
  <pre><code>db.restaurants.aggregate([{
      $unwind : {
          path: '$grades'
      }
  }, {
      $group: {
          _id: '$grades.date',
          grades: {
              $push: '$grades.grade'
          }
      }
  }])
  </code></pre>
  
  <p>Which gives me each date and the grades on that date.</p>
  
  <p>How do I now count the number of each unique grade?</p>