I am building an application where a user searches for a service provider based on location.
The following needs to be considered
- I save the lat, long for all the service providers and the radius of their servicing area say 5kms
- Users can search for service providers from any location and I grab the lat, long of the users current location from my frontend.
Lets consider I have the following details
Service providers: S1 : {lat: xxxx, long: xxxx, radius: 5km} S2 : {lat: xxxx, long: xxxx, radius: 6km}
and so on..
Now when a user searches from a particular lat, long I need to list all the service providers in a way where the user's lat, long falls inside the service providers radius.
That would be I need to list all the service providers where distance between user's geo point and Provider's geo point is less than the providers radius
How can I achieve this using mongodb geoSpatial queries ?