Du kan bruge $lookup med pipeline,
$match
vil markereactive
status$lookup
vil deltage i ledersamling$match
for at kontrollereleader_id
ogorganization
$match
check leaders er ikke[]
tom$project
for at fjerneleaders
felt
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 } }
])