我的藏品中有以下文件:
{
"_id" : ObjectId("539c118b310c022c947b0055"),
"term" : "aero storm tour",
"year" : "2015",
"month" : "06",
"day" : "01",
"hour" : "17",
"dayofyear" : "4",
"weekofyear" : "22",
"productcount" : 0,
"count" : 22
},
{
"_id" : ObjectId("558c118b310c022c947b1145"),
"term" : "aero",
"year" : "2015",
"month" : "06",
"day" : "01",
"hour" : "17",
"dayofyear" : "4",
"weekofyear" : "22",
"productcount" : 0,
"count" : 21
},
{
"_id" : ObjectId("558c992b310c022c947b0055"),
"term" : "aero storm tour",
"year" : "2015",
"month" : "06",
"day" : "01",
"hour" : "17",
"dayofyear" : "1",
"weekofyear" : "22",
"productcount" : 0,
"count" : 2
},
{
"_id" : ObjectId("558c118b123c022c947b0055"),
"term" : "aero storm tour",
"year" : "2014",
"month" : "06",
"day" : "01",
"hour" : "17",
"dayofyear" : "364",
"weekofyear" : "22",
"productcount" : 0,
"count" : 32
},
{
"_id" : ObjectId("558c223c310c022c947b0055"),
"term" : "aero storm tour",
"year" : "2014",
"month" : "06",
"day" : "01",
"hour" : "17",
"dayofyear" : "365",
"weekofyear" : "22",
"productcount" : 0,
"count" : 22
}
我需要根据count
和term
指定的条件计算year
和dayofyear
的总和。
我的查询:
db.tq.aggregate(
{$match:
{$or :[
{ $and :[{dayofyear:{ $gte : "1", $lte : "4" }},{year : "2015"}]},
{ $and :[{dayofyear:{ $gte : "363", $lte : "365" }},{year : "2014"}]}
]
}
},
{$group:{
_id :"$term",
totalcount : {
$sum : "$count"
}
}
},
{
$sort : {totalcount : -1}
}
)
在这里,我已手动指定日期为1和1之间。 2015年4月和Dayofyear 363& 365年2014年。
但它没有给出理想的结果。任何人都可以在我的查询中指出错误吗?