I'm new to mongodb and amazed by the fact that it handles geospatial coordinates and indexing/searching beautifully. However I have a scenario where any help would be appreciated.
I am developing an application that let's user find buses originating around a place and going to/around other place. I store the coordinates of every bus ride's starting point and ending point.
What I need is to find out is: any buses originating, say within 15 km radius and going to or around another place.
How do I do the query in mongodb/java?
My data is something like this (stores earth location coordinates): collection: travels
entry 1: { origin: 'x1', destination: 'y6', originCoords: [20,10], destCoords: [40,70] }
entry 2: { origin: 'x2', destination: 'y5', originCoords: [21,11], destCoords: [41,71] }
entry 3: { origin: 'x3', destination: 'y3', originCoords: [22,12], destCoords: [42,72] }
entry 4: { origin: 'x4', destination: 'y4', originCoords: [23,13], destCoords: [43,73] }
entry 5: { origin: 'x5', destination: 'y5', originCoords: [24,14], destCoords: [44,74] }
entry 6: { origin: 'x6', destination: 'y6', originCoords: [25,15], destCoords: [45,75] }
Now let's assume that
- x1 and x2 cities are located within 5 KM radius of each other.
- y5 and y6 cities are also located within 5 km radius of each other.
Now, if I want to search any buses originating around (5 km radius of) x1 and going to around (5 km radius of) y6 then how should I do that (assuming mongodb and java)?
Result must return entry1 and entry2.
Any suggestions or help would be much appreciated.