Можете да използвате по-долу aggregation
с mongodb 3.6 и по-горе
Трябва просто да използвате $match
с дъщерната колекция, както правите с родителската колекция в първия етап.
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"
}}
])