Das $match innerhalb von $lookup Die Pipeline hat keine Beziehung zur jobCollection Unterlagen. Es filtert die Dokumente nur nach tasks Sammlung. Sie müssen also ein weiteres $match verwenden Stufe nach dem $lookup um die ROOT(jobCollection ) Dokumente.
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": [] }}},
])