I have 3 collections: 'group10', 'group20' and 'parent'
I want to do $lookup in aggregation pipeline from one of these collections depending from condition in 'parent' collection.
Collection 'parent':
[{_id: 1, groupId: 10},
{_id: 2, groupId: 20}]
Collection 'group10':
[{_id: 1, groupId: 10, userData: 'A'},
{_id: 2, groupId: 10, userData: 'B'}]
Collection 'group20':
[{_id: 1, groupId: 20, userData: 'C'},
{_id: 2, groupId: 20, userData: 'D'}]
I tried next code:
$lookup: {
from: {
$cond: [{
$eq: ['$groupId', 10]
},
'group10',
'group20'
]
},
localField: 'groupId',
foreignField: 'groupId',
as: 'data'
}
but getting this error: 'from' option to $lookup must be a string, but was type object