OK, thanks for the clarification,
So the task here is to find the alliances that have the most routes between LHR and JFK, as shown in the
You’re starting with
air_routes. That’s a good start, since it has almost 67000 documents compared to
air_alliances 3. Generally, in a large collection, you want to start by selecting out the relevant documents with a $match stage. Once you’ve done that, then you can use the $lookup to cross-reference the results with air_alliances and process the final result to get your solution.
And there’s nothing in that sequence that would prevent you from using the results of $lookup in an aggregation stage. HTH.