title: Query in MongoDB for count rows (JasperSoft)
body: <p>I've an collection with 3 valuable fields (status, userid, sid).<br/>
  How can i count rows for each smtpid and each status? <br/>
  The status field can have values 0,1,2 or 3.</p>
  
  <p>For example:<br>
  sid status userid<br>
  125       0      200<br>
  125       0      213<br>
  156       1      154<br>
  123       2      584  </p>
  
  <p>Purpose:<br>
  sid  status count<br>
  125       0      2<br>
  156       1      1<br>
  123       2      1</p>
  
  <p>Query for getting example:  </p>
  
  <pre><code>{  
       runCommand : {  
      aggregate : 'sCollecion',  
      pipeline : [  
          { $match : { time : { '$gte' : '2014-01-01 00:00:00', '$lt' : '2014-01-01 02:00:00' } }  },  
          { $group : { _id : { StatusID : '$status', SID : '$sid' , UserID : '$userid'  } } }  
                      ]  
                  }  
  }
  </code></pre>