U kunt $lookup gebruiken met pijpleiding,
$match
zalactive
aanvinken status$lookup
zal lid worden van de leiderscollectie$match
omleader_id
te controleren enorganization
$match
controleer leiders is niet[]
leeg$project
omleaders
te verwijderen veld
db.teams.aggregate([
{ $match: { active: 1 } },
{
$lookup: {
from: "leaders",
let: { leader_id: "$leader_id" },
as: "leaders",
pipeline: [
{
$match: {
$and: [
{ $expr: { $eq: ["$_id", "$$leader_id"] } },
{ organization: "Software Development" }
]
}
}
]
}
},
{ $match: { leaders: { $ne: [] } } },
{ $project: { leaders: 0 } }
])