How to calculate timestamp difference in mongodb (in hours)?

前端 未结 1 1064
醉梦人生
醉梦人生 2020-12-21 03:41

Here\'s my data:

[
   {
       id: 1, 
       starttime: ISODate(\"2015-08-24T00:00:00.000Z\"), 
       endtime: ISODate(\"2015-08-24T07:00:00.000Z\")
   },         


        
相关标签:
1条回答
  • 2020-12-21 04:03
    db.collectionname.aggregate([
      {$project: {
          duration: {$divide: [{$subtract: ["$endtime", "$starttime"]}, 3600000]}
      }}
    ])
    
    0 讨论(0)
提交回复
热议问题