Duel.aggregate([
{ $match: query },
{ '$addFields': { 'photo1Id': { '$toObjectId': '$photo1' }, 'photo2Id': { '$toObjectId': '$photo2' } } },
{
$lookup: {
from: 'photoschemas',
localField: 'photo1Id',
foreignField: '_id',
as: 'photo1Info'
}
},
{$unwind: '$photo1Info'},
{
$lookup: {
from: 'photoschemas',
localField: 'photo2Id',
foreignField: '_id',
as: 'photo2Info'
}
},
{$unwind: '$photo2Info'}
}]
db.role.aggregate([
{ "$lookup": {
"from": "user",
"let": { "userId": "$_id" },
"pipeline": [
{ "$addFields": { "userId": { "$toObjectId": "$userId" }}},
{ "$match": { "$expr": { "$eq": [ "$userId", "$$userId" ] } } }
],
"as": "output"
}}
])