I am trying to implement a bus route listing application. My goal is to list buses that passes through two user given points(locations).
I am using mongodb in the backend. A simple structure of the data is like:
....
{ name: 'Bus-N', route: ["Loc1", "Loc2", "Loc3", "Loc4", "Loc5" ], startTime:'..'},
{ name: 'Bus-M', route: ["Loc2", "Loc3", "Loc4"], startTime:'..'}
....
Assumption: I have the list of all buses and for each bus I have all of it's travel routes.
User gives his start location and his destination as input.
- How can I use these inputs(start location and destination) to query across this database to list all the buses passing by the two points?
For example: If the input is
(Loc3, Loc4)I need the output as(Bus-N, Bus-M). - If there is a better way to implement this(which obviously there should be), please recommend the required changes.
I am new to mongodb. Please help with this, thanks in advance.
$allis what you're looking for: link. Tested it too..it works.db.collection.find({ route: { $all: ["Loc3", "Loc4"] } }).