title: How to group-by results of survey in mongodb and mongoose?
body: <p>I have an action collection in my app, which have the following objects structure:</p>
  
  <pre><code>    {
          "type" : "evMove",
          "userId" : "55fbbb2a34d594085988aa70",
          "data" : {
              "evId"   : "55fdaa53cca301f758f4023d",
              "moveId" : "55fdaa53cca301f758f4023f"
          }
      },
      {
          "type" : "game",
          "userId" : "55fgdfa34d594085988aa70",
          "data" : {
              ...
          }
      },
      {
          "type" : "evMove",
          "userId" : "55fbbb2aasd34d595988aa60",
          "data" : {
              "evId"   : "55fdaa53cca301f758f4023d",
              "moveId" : "55fdaa53cca301f758f4023f"
          }
      },
  {
          "type" : "evMove",
          "userId" : "55fbbb2a34d594085988aa30",
          "data" : {
              "evId"   : "55fdaa53cca301f758f4023d",
              "moveId" : "55fdaa53cca301f758f4023g"
          }
      }
  </code></pre>
  
  <p>I need to return a result in mongodb and mongoose that return the following:</p>
  
  <pre><code> for event id: 55fdaa53cca301f758f4023d
  
    moveId:55fdaa53cca301f758f4023d, count:2
    moveId:55fdaa53cca301f758f4023g, count:1
  </code></pre>
  
  <p>Which means the following if i do it in javascript and with no group by like query:</p>
  
  <pre><code>db.actions.find({'type':'evMove','data.evId':'55fdaa53cca301f758f4023d'})
  
   resultArray = {
         55fdaa53cca301f758f4023d : 0,
         55fdaa53cca301f758f4023g : 0
      };
      results.forEach(function(res){
           resultArray[res.data.evMove]++;
      );
  </code></pre>
  
  <p>How can i do the group by that will give me more or less the results i want (the move and the count of it) in mongodb and mongoose?</p>