'MongoDB Connect train routes

I have a collection of train routes that contain some "connecting" data. For example I have a source and destination field that looks like this

{
  "source": { "base": 1, "extra": 2},
  "destination": { "base": 3}
}

Where base and extra are ObjectIDs pointing to Locations in my database. Base locations contain information about the county and city, and extra locations also contain more specific informations about the location (like a landmark for example), the extra locations don't always appear in the route definition.

My routes also have information about the departureDate, departureTime, arrivalDate, arrivalTime.

I want to receive a source and destination ID in my request, which we don't know beforehand if it's a base or extra location and retrieve all routes that go from source to destination, keeping in mind that the connections should make sense regarding the dates and times of the route.

I'm thinking about using graphLookup but don't know exactly how to configure it to match either base or extra location and connect routes based on times and dates. Is there a better alternative?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source