你好,我正在获取我的time in和time out的数据。
"record": [{
"dateTime": {
"$date": "2021-09-17T04:13:39.465Z"
},
"status": "time-in",
}, {
"dateTime": {
"$date": "2021-09-17T04:14:01.182Z"
},
"status": "time-out",
}],
我想减去
中time out与time之间的时间差TIME OUT - TIME IN然后求和得到小时格式。
在Mongo 5.0中你可以使用新的函数$dateDiff
{
$set: {
diff: {
$dateDiff: {
startDate: { $first: "$record.dateTime" },
endDate: { $last: "$record.dateTime" },
unit: "hour"
}
}
}
}