Watch keynotes and sessions from MongoDB.live, our virtual developer conference.

Using MongoDB to store a Google Maps route

Hello! I am very new to Mongo and so I’m not at all familiar with it’s capabilities. I may be interested in switching over a project from SQL to NoSQL, but before I delve too deeply I wanted to get some opinions.

My goal is to be able to store an entire Google Maps route in a database. This would consist of an array of LatLng objects. Several thousand LatLng objects. Is Mongo capable of storing an array of this size? Is it advisable? Should I find another path forward?

A little background on what I am trying to accomplish. I am working on a ride share app. A user would be entering their departure point, destination point, and date. The database then returns all routes that match the date (as well as some other search criteria such as passenger number, etc). At this point, I need to determine which of the routes are within a particular distance to the departure and end points that the user entered.

What I am doing currently is making an Google API call for each returned route, using the route’s start and end point. I then compute the distance to this route from the API result. The problem is that the API calls are slow. On average, about 0.2 seconds per call. If I could simply get the route returned with the database query, I can reduce the processing time quite a bit.

So, is this possible using Mongo?? I should also add, that I am building the project using Laravel. Does anyone have experience running Mongo with Laravel? Is it easy to integrate? Are there other NoSQL options that might be better?

Many thanks for any input.

Hi, I think Mongo works very well for this use-case. Have you seen this page? https://docs.mongodb.com/manual/geospatial-queries/ It’s a very good starting point.
Regarding the max size of the array I’d say you can store large size of data as long as it’s below max size of BSON document (16MB). For more accurate info see this page: docs.mongodb.com/manual/reference/limits/#BSON-Document-Size
Also defining proper db indices would help a lot when it comes to query large volume of data.
For using Mongo in your Laravel project you may see this page about Mongodb PHP drivers: https://docs.mongodb.com/drivers/php/

Thanks so much for all the info. I think I’ll take the plunge and see what I can figure out.