reportingHierarchy
adalah array objek reguler di sini sehingga Anda dapat menambahkan $match
berikutnya tahap ke agregasi Anda
db.employees.aggregate( [
{
$graphLookup: {
from: "employees",
startWith: "$reportsTo",
connectFromField: "reportsTo",
connectToField: "name",
as: "reportingHierarchy"
}
},
{
$match: {
$and: [{ "reportingHierarchy.name": "Andrew" }, {"reportingHierarchy.name": "Eliot" }]
}
}
] )