I am trying to make a aggregate pipeline - $lookup
to receive from another
collection only items that are not equal to specific _id
for example :
You can use below aggregation with mongodb 3.6 and above
You need to just use $match
with the child collection as you do with the parent collection in the first stage.
db.BusinessCollection.aggregate([
{ "$match": { "clinics": { "$type": "array" }}},
{ "$lookup": {
"from": "ClinicsCollection",
"let": { "clinics": "$clinics" },
"pipeline": [
{ "$match": {
"$expr": {
"$and": [
{ "$in": ["$_id", "$$clinics"] },
{ "$not": { "$eq": ["$_id", 1] }}
]
}
}}
],
"as": "clinics"
}}
])