title: Group by date intervals
body: <p>I have a collection with documents like this:</p>
  <pre><code>{ datetime: new Date(), count: 1234 }
  </code></pre>
  <p>I want to get sums of <strong>count</strong> by <code>24 hours</code>, <code>7 days</code> and <code>30 days</code> intervals.</p>
  <p>The result should be like:</p>
  <pre><code>{ &quot;sum&quot;: 100,  &quot;interval&quot;: &quot;day&quot; }
  { &quot;sum&quot;: 700,  &quot;interval&quot;: &quot;week&quot; }
  { &quot;sum&quot;: 3000, &quot;interval&quot;: &quot;month&quot; }
  </code></pre>
  <p>In more abstract terms, I need to group results by multiple conditions (in this case — multiple time intervals)</p>
  <p>The MySQL equivalent would be:</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT 
      IF (time&gt;CURRENT_TIMESTAMP() - INTERVAL 24 HOUR, 1, 0) last_day,
      IF (time&gt;CURRENT_TIMESTAMP() - INTERVAL 168 HOUR, 1, 0) last_week,
      IF (time&gt;CURRENT_TIMESTAMP() - INTERVAL 720 HOUR, 1, 0) last_month,
      SUM(count) count
  FROM table
  GROUP BY    last_day,
              last_week,
              last_month
  </code></pre>