$match di dalam $lookup pipeline tidak ada hubungannya dengan jobCollection dokumen. Itu hanya menyaring dokumen untuk tasks koleksi. Jadi, Anda harus menggunakan satu lagi $match tahap setelah $lookup untuk menyaring ROOT(jobCollection ) dokumen.
jobCollection.aggregate([
{ "$match": { "$text": { "$search": "1234" }}},
{ "$lookup": {
"from": "task",
"let": { "job_id": "$_id" },
"pipeline": [
{ "$match": {
"$expr": {
"$and": [
{ "$eq": ["$job", "$$job_id"] },
{ "$eq": ["$status", "FAILED"] }
]
}
}}
],
"as": "tasks"
}},
{ "$match": { "tasks": { "$ne": [] }}},
])