Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I ensure decimal precision in mongodb geospatial coordinates?

I need to save longitude/latitude coordinates in mongodb and I'm not sure how to store them. No examples I see online show conversion to string or splitting up the decimal parts into 2 ints. I'm assuming that in order to enable geo indexing, I'd have to store them as doubles, so for example:

{ _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?

like image 489
Josh Kim Avatar asked Dec 20 '22 10:12

Josh Kim


1 Answers

MongoDB supports double datatype. It is used for all floating point numbers. As MongoDB implements BSON spec, we may think of it's double as of BSON double. Which is 8 bytes (64-bit IEEE 754 floating point) according to the specification. And it supports 15-17 significant digits.

So do not worry.

like image 143
madhead - StandWithUkraine Avatar answered May 06 '23 07:05

madhead - StandWithUkraine