【发布时间】:2017-02-23 11:11:59
【问题描述】:
我有一个类似以下数据集的集合,名为useragents。
我有一个用例是在每个useagents 中查找值的总和。在这种情况下,作为示例,我使用useragents 作为 Linux 和 Ubuntu 操作系统。它可以是动态的。作为我的第一步,我找到了使用聚合框架获取每个用户代理的聚合总和值的解决方案。
请参考这个background question。
但我想通过根据给定的参数列表检查每个venuelist、ssidlist、maclist 来汇总值。这对我来说是一个非常困难的问题,因为有时我的数据结构可能很复杂。
在给定以下参数的情况下,我想获得每个用户代理(linux、ubuntu)的总和:
参数列表 1
venueid :: [VID001, VID002] // this is compulsory field in parameter list ssids : [SSID001] // this is optional filed in parameter list mac : [22:22:22:22:22:22] output linux: 12 + 2 = 14 ubuntu : 2 + 5 = 7参数列表 2
venueid :: [VID001, VID002] // this is compulsory field in parameter list mac : [22:22:22:22:22:22] // this is optional filed in parameter list output linux: 12 + 4 + 2 = 16 ubuntu : 2 + 2 + 5 = 7
这是样本数据集
{
"_id" : ObjectId("57f940c4932a00aba387b0b0"),
"tenantID" : 1,
"date" : "2016-10-09 00:23:56",
"venueList" : [
{
"id" : “VID001”,
"sum" : [
{
"name" : "linux",
"value" : 16
},
{
"name" : "ubuntu",
"value" : 7
}
],
“ssidList” : [ // this is list of ssid’s in venue
{
"id" : “SSID001”,
"sum" : [
{
"name" : "linux",
"value" : 12
},
{
"name" : "ubuntu",
"value" : 2
}
],
“macList” : [ // this is mac list inside particular ssid ex: this is mac list inside the SSID1212
{
"id" : “22:22:22:22:22:22”,
"sum" : [
{
"name" : "linux",
"value" : 12
},
{
"name" : "ubuntu",
"value" : 2
}
]
}
]
},
{
"id" : “SSID002”,
"sum" : [
{
"name" : "linux",
"value" : 4
},
{
"name" : "ubuntu",
"value" : 5
}
],
“macList” : [ // this is mac list inside particular ssid ex: this is mac list inside the SSID1212
{
"id" : “22:22:22:22:22:22”, // this should be select in parameterlist 02 because there is no ssid selection in parameter list.
"sum" : [
{
"name" : "linux",
"value" : 4
},
{
"name" : "ubuntu",
"value" : 2
}
]
},
{
"id" : “44:44:44:44:44:44”,
"sum" : [
{
"name" : "linux",
"value" : 12
},
{
"name" : "ubuntu",
"value" : 3
}
]
}
]
}
]
},
{
"id" : “VID002”,
"sum" : [
"sum" : [
{
"name" : "linux",
"value" : 2
},
{
"name" : "linux",
"value" : 5
}
],
],
"ssidList" : [
{
"id" : “SSID001”,
"sum" : [
{
"name" : "linux",
"value" : 2
},
{
"name" : "linux",
"value" : 5
}
],
"macList" : [
{
"id" : “22:22:22:22:22:22”,
"sum" : [
{
"name" : "linux",
"value" : 2
}
{
"name" : "linux",
"value" : 5
}
]
}
]
}
]
}
]
}
请帮我解决这个问题,我将不胜感激。如果我的数据集也有任何问题,请提及。由于我是 MongoDB 的新手,因此您的 cmets 对我的帮助更大。
【问题讨论】:
-
希望这个能给你一个指导stackoverflow.com/questions/14568283/…
-
感谢您的回复。但我对如何在另一个参数内的多个参数中设置过滤结果有疑问。
-
在这种情况下,想要一个过滤结果的嵌套查询机制。我对如何在mongodb中生成查询有疑问
标签: mongodb mongoose mongodb-query aggregation-framework mgo