jjzjj

salesPerHour

全部标签

MongoDB 聚合 : average sales per hour

我有一个正在销售的系列。现在我需要获取某个日期范围内每小时的平均销售额。到目前为止,我有这样的查询:db.getCollection('sales').aggregate({"$match":{$and:[{"createdAt":{$gte:ISODate("2018-05-01T00:00:00.000Z")}},{"createdAt":{$lt:ISODate("2018-10-30T23:59:00.000Z")}},]}},{"$project":{"h":{"$hour":"$createdAt"},}},{"$group":{"_id":"$h","salesPerHo