geospatial - mongodb's ensureIndex doesn't work accurately -
mongodb version: osx-x86_64-2.4.5
i have collection of users geolocation data in following form:
[ { "_id" : "24128f74-3e47-4f02-8188-37779f3eca3c", "geolocation" : { "lat" : 55.5884705, "lng" : 13.0111425 } }, { "_id" : "65db4271-8eff-4619-95fb-08135cbccb8f", "geolocation" : { "lat" : 55.58934530000001, "lng" : 13.0066488 }, "email" : "stephan3@stephan3.com" }, { "_id" : "74d17da5-af4c-4386-9efa-9817f11b64f9", "geolocation" : { "lat" : 55.58934530000001, "lng" : 13.0066488 } }, { "_id" : "d0378d09-1f69-4e01-8602-b4805466a029", "geolocation" : { "lat" : 55.590957, "lng" : 13.001412 } } ]
as don't want migrate production data, created index able use geospatial queries such $geowithin documented here http://docs.mongodb.org/manual/tutorial/build-a-2dsphere-index/:
db.user.ensureindex({ geolocation : '2d'})
if query user collection in following way, empty array back
db.user.find({ geolocation: { $geowithin : { $center : [ [ 13.0111425,55.5884705 ], 1 ] } }});
note exact location user 24128f74-3e47-4f02-8188-37779f3eca3c, @ least should returned.
when convert users' geolocation property [ long, lat ] format, user entry looks following, , apply same query again, users, ones further away.
[ { "_id" : "24128f74-3e47-4f02-8188-37779f3eca3c", "geolocation" : [ 13.0111425, 55.5884705 ] }, ... ]
do have idea might going wrong?
Comments
Post a Comment