Why is the third option in the graphLookup Lab wrong?

By the time you get to the graphLookup, the airlines are filtered so why do we get an unfiltered connections result?

Hi @Brunilda_Metaj, welcome to the community.
After the first $lookup stage you will get an array of alliances in each airline document. But this won’t filter out all the documents where "alliance.name": "OneWorld" and hence even if any one of the alliance document match this query will be forwarded to the next stage. But we don’t want this behavior. As the question mentions:

… that are part of the “OneWorld” alliance …

Therefore, a better(and correct) strategy for this would be to first start with the alliances’ collection and then filter "OneWorld" alliance and then graphLookup on airlinescollection and then continuing withroutes` collection.

Thanks & Regards,
Sourabh Bagrecha,
MongoDB

so the {"$match": {"alliance.name": "OneWorld"}}, after the lookup doesnt correctly filter them out?

Hi @Brunilda_Metaj,
Yeah, that’s correct.

If you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
MongoDB