$graphLookup lab - wrong official solution

In this lab, I think the official solution might be wrong: https://university.mongodb.com/mercury/M121/2021_April_20/chapter/Chapter_3_Core_Aggregation_-_Combining_Information/lesson/5980bfbd92e612ebe564aa4a/problem
In the official solution they check that only the last airline in the path is valid.
I’m getting only 27 results for my solution (instead of 158).
Here is my solution:

var validAirlines = db.air_alliances.findOne({"name": "OneWorld"}).airlines;
  $match: { name: "OneWorld" }
}, {
  $graphLookup: {
    startWith: "$airlines",
    from: "air_airlines",
    connectFromField: "name",
    connectToField: "name",
    as: "airlines",
    maxDepth: 0,
    restrictSearchWithMatch: {
      country: { $in: ["Germany", "Spain", "Canada"] }
}, {
  $graphLookup: {
    startWith: "$airlines.base",
    from: "air_routes",
    connectFromField: "dst_airport",
    connectToField: "src_airport",
    as: "connections",
    maxDepth: 1,
    restrictSearchWithMatch: {
      "airline.name": { $in: validAirlines}
}, {
  $project: {
    "connections.dst_airport": 1,
    "connections.airline.name": 1
{ $unwind: "$connections" },
{ $group: { _id: "$connections.dst_airport" } }


1 Like

Hi @Rafael_Green,

Thanks for highlighting this!!

I will check your pipeline and verify the approach. Meanwhile, I would like to inform you that we are revamping the MongoDB Aggregation course to provide up-to-date content and an improved learner experience.

Given your keen observation, please let us know if you would be interested in beta testing our upcoming course.

Edit: I just noted your response in another post. Thanks for agreeing to beta test and we will keep you informed regarding the same.

Kind Regards,
Sonali Mamgain

1 Like