【发布时间】:2018-09-27 09:54:10
【问题描述】:
聚合后,我得到了一个非预期的输出。有什么我可以做的吗?
aggregate([
{ "$match": {
"CREATE_DATE": {
"$lte": new Date(),
"$gte": new Date(new Date().setDate(new
Date().getDate()-120))
}
} },
{ "$group": {
"_id": {
"month": { "$month": "$CREATE_DATE" },
"year": { "$year": "$CREATE_DATE" }
},
"avgofozone": { "$avg": "$OZONE" }
} }
])
实际输出:
[ { "avgofozone" : 21.07777777777778, "year" : 2018, "month" : 2 } { "avgofozone" : 17.8, "year" : 2018, "month" : 3 } { "avgofozone" : 17.8, "year" : 2018, "month" : 1 } ]
预期输出:
[ { "zone_type": "avgofozone", "year": 2018, "February": 21.07777777777778, "March": 17.8, "January": 17.8 } ]
【问题讨论】:
-
能否请您发布一个示例输入文档?
-
@Vega 我们可以显示月份名称整数 no prob { "_id" : ObjectId("5a65b71a3071ebb37576b3b56"), "ID" : "20180120210013631847000000", "DISTRICT" : "ntvp", "STATION" : “APPPCB”,“臭氧”:25.0,“FLAG1”:“NA”,“氨”:11.4,“苯”:6.7,“FLAG2”:“NA”,“FLAG3”:“NA”,“CREATE_DATE”: ISODate("2018-03-20T18:32:50.000Z"), "DATA_FROM" : "Gtuy" }
-
@Vega 我的预期输出是每个月的数字都替换为 avgofozone
标签: mongodb mongoose aggregation