ryanong / mongoid_spacial

A Mongoid Extention that simplifies and adds support for MongoDB Geo Spacial Calculations.
MIT License
138 stars 63 forks source link

fix for issue #5 #15

Open schnittchen opened 12 years ago

schnittchen commented 12 years ago

these modifications (up to 32b3a46) make the tests pass (except for one, just as before) on ruby 1.8.7 (tested with ree)

schnittchen commented 12 years ago

sorry, forgot that I had only run part of the tests while debugging. With 81257b8, all but two tests pass:

schnittchen commented 12 years ago

About the second failing test mentioned above: I missed that this was exactly the query syntax introduced by the gem. The test fails with

"geo values have to be numbers: { $maxDistance: 20.0, $near: [ 41.23, 2.9 ] }"

because mongodb geo queries are order sensitive in the hash (swapping $maxDistance and $near would make it work!). Though this could be fixed by using BSON::OrderedHash again, that would break other things... Python has the same issues: https://jira.mongodb.org/browse/PYTHON-292

This effectively means the new syntax introduced by the gem is not usable on ruby 1.8, however geoNear seems to work well, so one can use geoNear (if ordering by distance or obtaining the distance is required) and the old way

Bar.where(:location => {"$within" : {"$center" : [center, radius]}})

and its variants otherwise.

arthurnn commented 11 years ago

Do you mind squashing your commits together, and making sure everything still works before I merge it in ?