我使用了聚合函数。
{
"_id" : {
"orgId" : "af39bc69-1938-4149-b9f7-f101fd9baf73",
"userId" : "34adb4a0-0012-11e7-bf32-cf79d6b423e9"
},
"lastSeen" : ISODate("2018-01-19T18:49:52.242+05:30"),
"firstSeen" : ISODate("2018-01-19T10:08:21.026+05:30"),
"totalHourSpent" : NumberLong("31291216")
},
{
"_id" : {
"orgId" : "af39bc69-1938-4149-b9f7-f101fd9baf73",
"userId" : "679416b0-3f88-11e7-8d27-77235eb1ba9b"
},
"lastSeen" : ISODate("2018-01-19T20:51:30.946+05:30"),
"firstSeen" : ISODate("2018-01-19T11:07:44.256+05:30"),
"totalHourSpent" : NumberLong("35026690")
},
当我执行此查询时,mongo以毫秒为单位返回 totalHourSpent ,如下所示。
julia> replace(string1,r"(-?\d+\.?\d*|-?\d*\.?\d+)", x -> round(parse(Float64, x), 2))
"-123.46/EI + 2345.68/EA"
julia> replace(string1,r"(-?\d+\.?\d*|-?\d*\.?\d+)", x -> @sprintf("%.2f", parse(Float64, x)))
"-123.46/EI + 2345.68/EA"
如何以小时计算 totalHourSpent 。提前致谢。
答案 0 :(得分:3)
返回的工厂可以通过除以1000 * 60 * 60(3600000)
转换为小时totalHourSpent:{$divide : [{$subtract: ["$lastSeen","$firstSeen"]}, 360000]}
即
35026690÷3600000=9.72963611111111 hours