mongodb shard geo documents

110 views Asked by At

I have documents which store the lat/long cooridnates, timestamp, and a little bit of metadata. I have ran into a problem where I need to start to shard now. The only operation I run on these documents is I run a nearest search which return all the documents within 1km of a point I specify, and orders by newest. Since Geospatial data can't be sharded in MongoDB, what is the most efficient way to shard this data?

1

There are 1 answers

0
chridam On

Would recommend including two separate fields in your collection that store the longitude and latitude separately and use those keys to create a compound key which you can then use as a shard key. For example:

{ 
    location: [ <longitude> , <latitude> ],
    lng: <longitude>, 
    lat: <latitude> 
}