是否有可能在mongodb或mongoose中使用条件查找源('from'),如下所示
Collection.aggregate([
{
'$match': {
'receivers.user': new ObjectId('..........')
}
}, {
'$lookup': {
'from': $switch: {
type: [
{ case: 101, then: collection1 },
{ case: 102, then: collection2 },
]
},
'localField': 'data.on_behalf',
'foreignField': '_id',
'as': 'data.on_behalf'
}
}, {
'$unwind': {
'path': '$data.on_behalf',
'preserveNullAndEmptyArrays': true
}
}
])
我想根据类型值切换我的查找集合。
是否有可能在mongodb或mongoose中使用条件查找源('from'),如下所示Collection.aggregate([{'$ match':{'receivers.user':new ObjectId('。 .....'...
如果只有两个案例,则可以使用条件运算符来指定要从中进行查找的集合: