我有如此大的CDR(呼叫详细报告)数据:
{
"_id" : ObjectId("54eecc9a6c6852b9f0575bbb"),
"msisdn" : "9818895866",
"callType" : "NA",
"duration" : 13.5,
"charges" : 200,
"traffic" : "Data",
"Date" : ISODate("2014-02-15T12:15:42.535Z")
}
{
"_id" : ObjectId("54eecc9a6c6852b9f0575bbc"),
"msisdn" : "9818356561",
"callType" : "STD",
"duration" : 20.100000381469727,
"charges" : 100,
"traffic" : "Voice",
"Date" : ISODate("2014-01-09T00:11:14.646Z")
}
{
"_id" : ObjectId("54eecc9a6c6852b9f0575bbd"),
"msisdn" : "9818173670",
"callType" : "NA",
"duration" : 19.399999618530273,
"charges" : 300,
"traffic" : "Data",
"Date" : ISODate("2014-01-13T19:48:47.789Z")
}
{
"_id" : ObjectId("54eecc9a6c6852b9f0575bbe"),
"msisdn" : "9818719936",
"callType" : "Local",
"duration" : 9,
"charges" : 350,
"traffic" : "SMS",
"Date" : ISODate("2014-03-02T10:51:29.846Z")
}
{
"_id" : ObjectId("54eecc9a6c6852b9f0575bbf"),
"msisdn" : "9818612562",
"callType" : "STD",
"duration" : 5.110000133514404,
"charges" : 450,
"traffic" : "Voice",
"Date" : ISODate("2014-01-08T16:41:30.327Z")
}
我想显示使用TRAFFIC =“DATA”上个月持续时间的总和>当月持续时间总和* 2
仅显示更大的msisdn字段的总和
我试过这个
db.CDR.aggregate([ { $match : { traffic : "Data" }},{"$group" : {
"_id" : {
"Msisdn" : "$msisdn",
"Month" : "$date"
},
"Total Duration" : {
"$sum" : "$duration"
},
"Count" : {
"$sum" : 1
}
}
}])
显示持续时间的所有时间总和。
我想按月进行分组并比较每个月并仅显示更大的msisdn。