Location coordinates as a fragment key in MongoDB

Is it possible to have lat and long coordinates as a fragment key in a geospatial index collection in mongoDB? If not, can you suggest an efficient way to calculate the fragment key on a location based applcation server?

+4
source share
1 answer

You cannot use the geospatial index as the index of a fragment key.

Pay attention to the note "Important": http://docs.mongodb.org/manual/core/2d/#d-indexes

Important; . You cannot use the 2d index as a shard key when plastering a collection. However, you can create and maintain a geospatial index on the outlined collection using another field as the fragment key.

You also cannot use an array field as a fragment key. Thus, the only way you can do this is to save your location twice, once, as an indexed geodetic array with index 2d, and again as two regular fields that you can create a normal composite index, and then overlay on that composite key.

However, since the fragment key is immutable, make sure your location field is final, i.e. that it is always known at the time of creation and cannot be changed.

+10
source

Source: https://habr.com/ru/post/1479030/


All Articles