nitesh goel
nitesh goel

Reputation: 6406

The best way to store given lat, long and address in mongo db such that finding address for a given lat, long is fast

I am scratching my head around from past two days to get it right. I have a live data set of around 20M lat, long and address. Now, I want to store them in MongoDB such that query to find the address for a given lat, long is fast. Some of the solutions that I found on MongoDB are :

  1. index loc with 2dsphere.

but how good is find query for an exact match of lat, long?

  1. If not using 2dsphere then what is the best way to store lat, long so that keep storage and index size at the minimum and get the performance.

Upvotes: 0

Views: 804

Answers (1)

Evan
Evan

Reputation: 313

MongoDB uses a GeoHash and a B-tree internally for its 2dsphere indices, which provides very fast area lookups using $near and $geoNear; you can use $minDistance and $maxDistance of 0 for exact matches but you may want to use a $maxDistance of 1 if you're worried about issues relating to floating point precision. In many cases it can be important to limit(1) your results if they are densely distributed in some places, although for street addresses that should not be an issue. On my dev machine I can query a collection with 40 million polygons, totalling nearly 50GB of data, in 300-400 ms.

Upvotes: 1

Related Questions