我正在学习MongoDB汇总管道,我试图从$unwind
和$group
的输出中获得匹配计数。我能够看到$unwind
和$group
的结果。但我不确定为什么我没有得到匹配的计数。请帮忙让个场大于25
下面是一个例子文件:
{
"_id":ObjectId("599e9dbd8fbad926e712f902"),
"sample":"1",
"attribute":[
{
"functionName":"1",
"percentage":31.6
}
]
}
我尝试这样做:
db.docs3.aggregate({
$unwind:'$attribute'
},
{
$group:{
_id:{
func:"$attribute.functionName",
percen:"$attribute.percentage"
}
}
})
,并得到这样的输出:
{ "_id" : { "func" : "7", "percen" : 30 } }
{ "_id" : { "func" : "5", "percen" : 23.1 } }
{ "_id" : { "func" : "8", "percen" : 27.8 } }
{ "_id" : { "func" : "6", "percen" : 32.1 } }
{ "_id" : { "func" : "1", "percen" : 31.6 } }
{ "_id" : { "func" : "2", "percen" : 35 } }
{ "_id" : { "func" : "3", "percen" : 7.1 } }
{ "_id" : { "func" : "4", "percen" : 31.6 } }
我试过这个:
db.docs3.aggregate({
$unwind:'$attribute'
},
{
$group:{
_id:{
func:"$attribute.functionName",
percen:"$attribute.percentage"
}
}
},
{
$match:{
"attribute.percentage":{
$gt:25
}
}
})
我得到一个错误。
喜毛刺相同的字段名称,感谢您的答复。其实我试图获得> 25的百分比functionName的列表。 –
@ ManiMuthu.K你可以请更新问题,包括一个示例文件,显示你想要的输出?这是表达您的要求的最明确的方式。 – glytching