title: MongoDb aggregation Group by Date
body: <p>I'm trying to group by timestamp for the collection named "foo" { _id, TimeStamp }</p>
  
  <pre><code>db.foos.aggregate(
  [
     {$group : { _id : new Date (Date.UTC({ $year : '$TimeStamp' },{ $month : '$TimeStamp' },{$dayOfMonth : '$TimeStamp'}))       }}
  ])
  </code></pre>
  
  <p>Expecting many dates but the result is just one date. The data i'm using is correct (has many foo and different dates except 1970). There's some problem in the date parsing but i can not solve yet.</p>
  
  <pre><code>{
      "result" : [ 
          {
              "_id" : ISODate("1970-01-01T00:00:00.000Z")
          }
      ],
      "ok" : 1
  }
  </code></pre>
  
  <p>Tried this One:</p>
  
  <pre><code>db.foos.aggregate(
  [
     {$group : { _id : { year : { $year : '$TimeStamp' }, month : { $month : '$TimeStamp' }, day : {$dayOfMonth : '$TimeStamp'} }, count : { $sum : 1 }       }},
     {$project : { parsedDate : new Date('$_id.year', '$_id.month', '$_id.day') , count : 1, _id : 0} }
  ])
  </code></pre>
  
  <p>Result : </p>
  
  <pre><code>uncaught exception: aggregate failed: {
      "errmsg" : "exception: disallowed field type Date in object expression (at 'parsedDate')",
      "code" : 15992,
      "ok" : 0
  }
  </code></pre>
  
  <p>And that one:</p>
  
  <pre><code>db.foos.aggregate(
  [
     {$group : { _id : { year : { $year : '$TimeStamp' }, month : { $month : '$TimeStamp' }, day : {$dayOfMonth : '$TimeStamp'} }, count : { $sum : 1 }       }},
     {$project : { parsedDate : Date.UTC('$_id.year', '$_id.month', '$_id.day') , count : 1, _id : 0} }
  ])
  </code></pre>
  
  <p>Can not see dates in the result</p>
  
  <pre><code>{
      "result" : [ 
          {
              "count" : 412
          }, 
          {
              "count" : 1702
          }, 
          {
              "count" : 422
          }
      ],
      "ok" : 1
  }
  </code></pre>