How to calculate timestamp difference in mongodb (in hours)?
<p>Here's my data: </p>

<pre><code>[
   {
       id: 1, 
       starttime: ISODate("2015-08-24T00:00:00.000Z"), 
       endtime: ISODate("2015-08-24T07:00:00.000Z")
   },
   {
       id: 2, 
       starttime: ISODate("2015-08-24T20:00:00.000Z"), 
       endtime: ISODate("2015-08-25T01:00:00.000Z")
   }
]
</code></pre>

<p>can I make a mongodb query to display duration (or in this case a difference operation) of starttime and endtime with results like:</p>

<pre><code>[ {id:1, duration: 7}, {id: 2, duration: 5}]
</code></pre>

<p>Notice that timestamp can have different date so <code>$hour</code>(aggregation pipeline) might not work. Can anyone help ? Thank you</p>