title: Mongo query count n+1 scenario
body: <p>Given a mongo collection with properties "createdDate", "eventType"  and few other, I want to query for documents between a give date range and list the count by eventType.
  As of now I have a lengthy approach:</p>
  
  <ul>
  <li>Query for distinct <code>eventType</code> between given date range</li>
  </ul>
  
  <pre><code>db.EventMessage.distinct( "eventType" , { "env" : "prod" });
  </code></pre>
  
  <p>Lets say this query yeilds, Foo1EventType,Foo2EventType, Foo3EventType etc.</p>
  
  <ul>
  <li>For each of the eventType from the above, query document count for given date range</li>
  </ul>
  
  <pre><code>db.EventMessage.count ( { "eventType" : "Foo1EventType" ,  "createdDate" :  {"$gte": new Date("2015-05-22") , "$lt" : new Date("2015-05-23") }  });
  </code></pre>
  
  <p>Above query gives me the count of events for Foo1EventType between the dates range specified. However I need to run this query for each eventType separately. I want to check for better performing query which iterates over all distinct eventTypes and lists the count against the eventType.<br>
  MongoDB contains more than 50K documents/day and total 6 months data is maintained at any point in time.</p>
  
  <p>Is there a better performing query to yield the count by each eventType for given range of dates?</p>