我需要编写一个查询[aggregate],它返回Mongodb中两个日期之间的平均小时费率。
我在研究中发现了以下代码
db.transactions.aggregate([
{
$match: {
transactionDate: {
$gte: ISODate("2017-01-01T00:00:00.000Z"),
$lt: ISODate("2017-01-31T23:59:59.000Z")
}
}
}, {
$group: {
_id: null,
average_transaction_amount: {
$avg: "$amount"
}
}
}
]);
前面的代码返回两个日期之间的平均值,但我需要每小时平均值。
示例文档是
{"_id":"5a4e1fa1e4b02d76985c39b1",
"temp1":4,
"temp2":3,
"temp3":2,
"created_on":"2018-01-04T12:35:45.833Z"}
结果例如:
{ {temp1:5,temp2:6,temp3:6} for Average hour {temp1:2,temp2:4,temp3:6}for Average hour next ,{temp1:5,temp2:7,temp3:9},{temp1:8,temp2:4,temp3:7},{temp1:4,temp2:2,temp3:6},{temp1:9,temp2:6,temp3:4}
}
每小时之间有很多值,所以我需要计算每小时的平均值
请帮忙