title: How to use $dayOfYear aggregation with epoch timestamps
body: <p>I have my documents in this format:</p>
  
  <pre><code>{
      "_id": 1517209200000,       
      "timestamp": 1517209200000,
      "current": 236078,
  }
  </code></pre>
  
  <p>Timestamp is an epoch representation of a date, with about 100 documents inserted per day. It's stored as a number.</p>
  
  <p>I'm trying to figure out how to print last 30 days with average <code>$current</code> as well as min and max for each day.</p>
  
  <p>I found the $dayOfYear aggregation however I am not sure how to apply it to my epoch timestamps.
  (<a href="https://docs.mongodb.com/manual/reference/operator/aggregation/dayOfYear/" rel="nofollow noreferrer">https://docs.mongodb.com/manual/reference/operator/aggregation/dayOfYear/</a>)</p>
  
  <p>Could anyone share their knowledge if they know the answer?</p>
  
  <p>Thank you</p>
  
  <p>EDIT: my first attempt that returns an error: <code>"errmsg" : "can't convert from BSON type double to Date",</code></p>
  
  <pre><code>db.cable23.aggregate([ { $match: {'direction': 0} },{$group : {'_id': {'$year': "$timestamp"}}}])
  </code></pre>