title: How to extract grouped results from an array inside a collection in Mongodb
body: <p>I am working with the Foursquare API using NodeJS and Mongodb on the backend side. I have all the user information and checkin history stored in a collection. So the collection looks similar to this:</p>
  
  <pre><code>{
      _id: ...,
      foursquareId: ...
      personalInfo: {},
      checkins: [
          {
              id: ...,
              createdAt: 123456789  //Seconds since epoch&gt;,
              venue: {},
              ...
          },
          {
              id: ...,
              createdAt: 123456789  //Seconds since epoch&gt;,
              venue: {},
              ...
          },
          ...
      ]
  } 
  </code></pre>
  
  <p>For this question I am only interested to the checkins array. I need to return a list of checkins quantity by month and year, but I am not sure which is the best way to approach this. I think that the result would be something like this: (I am not totally convinced though)</p>
  
  <pre><code>{
      '2016': {
          'January': 43,
          'February': 38,
          'March': 40,
          'April': 48,
          'May': 50,
          'June': 41,
          'July': 39,
          'August': 38,
          'September': 30,
          'October': 29,
          'November': 38,
          'December': 41
      },
      '2017': {
          'January': 55,
          'February': 20
      }
  }
  </code></pre>
  
  <p>I am not interested about the way I receive the information on the frontend. <strong>I want to know if is possible to do this in mongodb</strong> because I couldn't find a way to do it on their documentation or any other example here. Otherwise I might need to do it in the frontend (not a good idea...so I could have around 7k results or more on this array...).</p>