我正在尝试准备聚合查询,以获得更快的深度嵌套元素计数,集合相当大(100M docs/1TB/mongodb 4.4),因此任何$unwind的使任务非常缓慢,请,建议如果有任何选项使用$reduce/$filter或其他更快的选项:
示例文档:
{
"_id": ObjectId("5c05984246a0201286d4b57a"),
f: "x",
"_a": [
{
"_onlineStore": {}
},
{
"_p": [
{
"pid": 1,
"s": {
"a": {
"t": [
{
id: 1,
"dateP": "20200-09-20",
lang: "EN"
},
{
id: 2,
"dateP": "20200-09-20",
lang: "En"
}
]
},
"c": {
"t": [
{
id: 3,
lang: "en"
},
{
id: 4,
lang: "En"
},
{
id: 5,
"dateP": "20300-09-23"
}
]
}
},
h: "Some data"
}
]
}
]
}
我需要计算"_a []._p []._s.c. t []"数组元素的数量,其中lang:美元:["恩"、"恩"、"恩"、"恩"、"恩"]
注:"_a._p._s.a. t"或"_a._p._s.d. t"项下的元素不应计入...
预期成果1:
{ count:2}
预期成果2:
{
id: 3,
lang: "en"
},
{
id: 4,
lang: "En"
}
拜托,给点建议?
谢谢
1.Extended example that need to be fixed playground (count expected to be 8)
这是我的放松版本,但对于大收藏来说,它看起来相当昂贵:
2. Playground unwind version ( expensive )
1条答案
按热度按时间pqwbnv8z1#
])