How can I ensure decimal precision in mongodb geospatial coordinates?
I need to store longitude / latitude coordinates in mongodb and I'm not sure how to store them. There are no examples where I see an online cast of converting to string or dividing decimal parts into 2 intervals. My guess is that in order to enable geo-indexing, I would have to store them as doubles, e.g .:
{ _id : 100, pos: { long : 126.9, lat : 35.2 }, type : "restaurant"}
I need at least 6 decimal places of precision, so how does this work in mongodb?
MongoDB supportsdouble
data type. It is used for all floating point numbers. Since MongoDB implements the BSON specification, we can think of it as double BSON. This 8 bytes (64-bit IEEE 754 floating point)
is according to the specification . And it supports 15-17 significant digits.
So don't worry.
... You can adjust the hash precision to 32 bits , which gives the equivalent of approximately 8 or 9 decimal places of precision. This way you will lose some precision from the pairs, but still a lot for your application.