$graphLookup lab - wrong official solution

Hi,
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;
db.air_alliances.aggregate([{
  $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" } }
])

Thanks,

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

Hi @Sonali_Mamgain,
Have you checked this issue?
Thanks,
Rafael,

Hi @Rafael_Green,

Thank you for following up on this. I’ve compared your solution with the solution that is listed in the course, and I believe that your solution can be considered correct. The problem with this exercise is that the question statement has room for interpretation which means that your solution is correct given your interpretation of the question.

As Sonali said, we are working on a new course that will eliminate long-winded ambiguous questions and leave less room for interpretation.

In the meantime, I’m more than happy to give you credit for the solution to this problem in the course.

Let me know if you have any additional questions or concerns.

4 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.