Start a new topic

Geospatial data: approach


could you please answer my questions about geospatial data?

1. Is "_geoloc" field "Kinvey specific"? I mean can I create my own field say "location" and specify data for it or it must be "_geoloc"? I don't see any reason to keep only this name "_geoloc" as all the work is done my MongoDB.

2. What is the right approach to save the geospatial data in the database? For example I have list of points for the specific route, so the data structure could be like:

"route": {

"points": [

{"loc": [40, 50],

"name": "Camping"},

{"loc" : [40, 70],

"name": "Black sand beach"}



Another approach is to have all the points in the specific collection and a route would just reference to these points:

"route": {

"points": [

{"_id": 123},

{"_id": 125}



Which approach is better/suitable if I want to apply some geospacial queries or there is no any difference except the query itself?


Hey guys I understand you are very busy, but I hoped you are able to find couple of minutes to answer these 2 very simple question...
Sorry for the delay!

1. In order to run geo queries MongoDB must create a special geo index that's all handled in the background! However you must put the geo data into the field named _geoloc for it work properly. You cannot change the name of this field.

2. Since your points have attributes the best way is to break the object into multiple entities of a single collection. For example, `{... "name": "Camping", "_geoloc": [40, 50]}

{... "name": "Black sand beach", "_geoloc": [40,70] }`

There isn't a better way to do it, it would just be too complicated to constructor queries otherwise.

_Note: if the points didn't have attributes you could stuff them all into an array of the _geoloc field. see [mongodb's docs]( "mongodb's docs") for more details_

Hi Morgan, thanks for your answer.
Login or Signup to post a comment