mongomapper geospatial 'within' query

空扰寡人 提交于 2019-12-11 11:55:01

问题


I'm trying to do a 'within' query using mongomapper. When I execute the command in the shell everything works fine:

box = [[32.476750,-117.246094],[32.850173,-116.806641]]
db.locations.find({"location" : {"$within" : {"$box" : box}}})
// Bunch of results

However, when I run the same in the rails console I get nil:

box = [[32.476750,-117.246094],[32.850173,-116.806641]]
Location.find(:location => {"$within" => {"$box" => box}})
 => nil 

If I do Location.first I get a location back so I do know that I'm pointing at the correct db collection. What am I doing wrong with my mongomapper query that's returning 0 results?


回答1:


Ah, I figured it out. Instead of using 'find' I used 'where' instead. Now I'm getting the correct result set back.



来源:https://stackoverflow.com/questions/9853666/mongomapper-geospatial-within-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!