相关疑难解决方法(0)

如何在mongodb中减去两个日期时间

我已经使用了聚合函数。

db.checkins.aggregate([
       {$match: {checkinType: "Beacon",
               "associationIds.organizationId":"af39bc69-1938-4149",
               "checkinData.time": {"$gte": new Date("2018-01-18T18:30:00.000Z"), 
                                   "$lt": new Date("2018-01-19T18:30:00.000Z")}
                }
        },
       {"$sort":{"checkinData.time":-1}},
       {$group: {"_id":
                    {"orgId":"$asst.organizationId", "userId":"$asst.userId"},
                    "lastSeen":{"$first":"$checkinData.time"},
                   "firstSeen":{"$last":"$checkinData.time"},
               }
       }, 
      {"$project":{"_id":1,"lastSeen":1, "firstSeen":1, 
                  totalHourSpent:{$subtract: ["$lastSeen","$firstSeen"]}}}, 
  ])
Run Code Online (Sandbox Code Playgroud)

当我执行此查询mongo时,以毫秒为单位返回totalHourSpent,如下所示。

{
  "_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")
 },
Run Code Online (Sandbox Code Playgroud)

如何以小时为单位计算totalHourSpent。提前致谢。

aggregate mongodb node.js mlab

3
推荐指数
1
解决办法
5885
查看次数

meteor,mongodb,spacebars,我如何只显示2位小数

我有一个具有类似值的集合,{ "pctFail" : "0.3515500159795462" }当我将其传递给模板并显示为{{myTemplate}}%时,它在我的html中显示为0.3515500159795462%.我如何将其显示为0.35%?

mongodb meteor spacebars

2
推荐指数
1
解决办法
905
查看次数

标签 统计

mongodb ×2

aggregate ×1

meteor ×1

mlab ×1

node.js ×1

spacebars ×1