Collection store 包含嵌套的文档.使用聚合框架,我希望从store 获得所有文档,其中"Products"字段中的UID将被集合产品中的实际产品文档替换.
我有两个这样的Collection :
// collection Shops
[
{
"name": "Shop A",
"countries": [
{
"name": "Germany",
"cities": [
{
"name": "Berlin",
"districts": [
{
"name": "First District",
"products": [1, 2, 3]
},
]
}
]
}
]
}
]
// collection Products
[
{
"uid": 1,
"name": "Banana",
},
{
"uid": 2,
"name": "Apple",
},
{
"uid": 2,
"name": "Peach",
}
]
Desired outcome:个
[
{
"name": "Shop A",
"countries": [
{
"name": "Germany",
"cities": [
{
"name": "Berlin",
"districts": [
{
"name": "First District",
"products": [
{
"uid": 1,
"name": "Banana",
},
{
"uid": 2,
"name": "Apple",
},
{
"uid": 2,
"name": "Peach",
}
]
},
]
}
]
}
]
}
]
我按照描述的here in the mongo docstry 了$lookup
,但对于这种嵌套的文档 struct 不起作用.
谢谢你的帮忙!