【发布时间】:2021-10-11 10:56:38
【问题描述】:
我有三个集合:A、B、C。
A 有一个名为 a 的属性,它是 B 或 C 中的一个 ref id。
我要做的是,先在B中查找,如果没有找到,然后在C中查找。
类似这样的:
[
{
$lookup:
{
from: 'B',
localField: 'a',
foreignField: '_id',
as: 'temp'
}
},
{
$unwind:
{
path: '$temp',
preserveNullAndEmptyArrays: true
}
},
{
$lookup:
{
if: 'temp not exist', <! just demonstrate !>
from: 'C',
localField: 'a',
foreignField: '_id',
as: 'temp'
}
},
]
我不知道如何实现。有人可以帮忙吗?谢谢。
【问题讨论】:
-
请提供每个集合的样本数据