title: mongodb: find summary of records
body: <p>I have a collection called 'tickers'</p>
  
  <p>Data is formatted as:</p>
  
  <pre><code>{
    "_id": ObjectId("50d192b5480cf44157000000"),
    "ticker": {
      "high": 13.38839,
      "low": 13.1225,
      "avg": 13.244705635,
      "vwap": 13.258414151,
      "vol": NumberInt(21562),
      "last_all": 13.57334,
      "last_local": 13.3324,
      "last": 13.3324,
      "buy": 13.33185,
      "sell": 13.3749
     },
    "date": ISODate("2012-12-19T10: 11: 01.439Z")
   }  
  </code></pre>
  
  <p>Data is inserted every <strong>minute</strong> from the price quotes and transactions.</p>
  
  <p>I want to find the average for every <strong>hour</strong> from the above data.</p>
  
  <p>I tried:</p>
  
  <pre><code>command(array(
   'aggregate' =&gt; 'tickers',
   'pipeline' =&gt; array( 
          array( 
         '$group' =&gt; array( 
          '_id' =&gt; array(
              'year'=&gt;'$year($date)',
          'month'=&gt;'$month($date)',
          'day'=&gt;'$dayOfMonth($date)',
          'hour'=&gt;'$hour($date)'
      ),
              'avg' =&gt; array( '$avg' =&gt; '$ticker.avg') ,
                  ),                      
                )))
  </code></pre>
  
  <p>But only get one record as out put:</p>
  
  <pre><code>   Array ( 
       [result] =&gt; Array (
         [0] =&gt; Array ( 
               [_id] =&gt; Array ( ) 
               [avg] =&gt; 13.407843889084 ) ) 
      [ok] =&gt; 1 
    ) 
  </code></pre>
  
  <p>Expecting at least 100 records for 100 days...</p>