【发布时间】:2018-09-01 11:59:30
【问题描述】:
我正在尝试此聚合最近 4 个月记录每个月的臭氧平均值但平均值为空如何获得平均值
db.Air_pollution.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"}}},
{$sort:{"year":-1}},{$project:
{year:'$_id.year',month:'$_id.month',_id:0,avgofozone:1}}
])
输出:
{ "avgofozone" : null, "year" : 2018, "month" : 2 }
{ "avgofozone" : null, "year" : 2018, "month" : 3 }
{ "avgofozone" : null, "year" : 2018, "month" : 1 }
【问题讨论】:
-
请发布样本数据集
-
@Rahul Raj "_id" : ObjectId("5ab3f0975c4f698c8a39ea22"), "DISTRICT" : "vskp", "STATION" : "appcb", "TAKEN_DATE" : ISODate("2018-02-25T00 :18:00.000Z")、“臭氧”:“8:84”、“pm10”:“69.0”、“pm2dots”:“49.0”、“DATA_FROM”:“vsk”、“CREATE_DATE”:ISODate(“2018 -02-05T00:30:05.867Z")
标签: mongodb mongoose mongodb-query aggregate-functions mongoose-schema