【发布时间】:2021-03-03 17:13:39
【问题描述】:
我有以下收藏
用户
[
{
id : 'acd-1234',
name : 'some name',
profile_id : 1,
is_graduate: true,
children: [
{ class: 'User', id: 'abcd-123'},
{ class: 'User', id: 'bcd-33'}
]
},
{
id: 'abcd-123',
name : 'jhon',
profile_id : 2
is_graduate: true,
},
{
id: 'bcd-123',
name : 'jhon due',
profile_id : 3,
is_graduate: false
}
]
个人资料
[
{
id: 1,
address: 'some address'
},
{
id: 2,
address: 'some other address'
},
{
id: 3,
address: 'some other other address'
}
]
我需要的最终输出是(父母只有研究生)
[
{
id: 'acd-1234',
name: 'some name',
is_graduate: true,
profile : {
id: 1,
address: "some address"
},
children: [
{
id: "abcd-123",
name: "jhon",
is_graduate: true,
profile: {
id: 2,
address: "some other address"
}
}
]
}
]
我真正陷入困境的地方是
- 进行嵌套查找。显示所有孩子的个人资料
- 对孩子应用过滤
来自 mongo 的以下错误不允许我使用带有 localField 的管道
$lookup with 'pipeline' may not specify 'localField' or 'foreignField'
【问题讨论】:
标签: mongodb mongodb-query aggregation-framework