mongodb time gap between two timestamps
// { _id: 1, start: ISODate("2015-08-24T00:00:00Z"), end: ISODate("2015-08-24T07:00:00Z") }
// { _id: 2, start: ISODate("2015-08-24T20:00:00Z"), end: ISODate("2015-08-25T01:00:00Z") }
db.collection.aggregate([
{ $project:
{ duration:
{ $dateDiff: { startDate: "$start", endDate: "$end", unit: "hour" } }
}
}
])
// { "_id" : 1, "duration" : 7 }
// { "_id" : 2, "duration" : 5 }