数据格式如下:
{
"_id" : 1,
"ft" : "云功能",
"pro" : "江苏省",
"pid" : 3,
"prid" : 320000,
"guid" : "20140904abcdefabcd10000000",
"fn" : "云检查",
"ct" : "无锡市",
"hds" : "76332f9bafe7aff580e47e42df07e5c7",
"cid" : 320200,
"ut" : new Date("1/9/2014 20:01:00"),
"un" : "shao1"
}
需求:根据用户进行聚合操作,聚合出某个时间之内的用户的使用ft的次数,最后根据使用次数进行过滤。
db.Log.aggregate([
{$match: {"ft":1,"ut":{$lt:ISODate("2014-08-19 00:00:00")}}},
{$group: {
_id: {un:"$un"},
count: { $sum: { $cond: [ { $gt: [ "$pid",0 ] },1,0] }}
}},
{$project:{un:1,count: 1}},
{$match: {"count":{$gt: 1}}}
]);