本文介绍了mongomapper地理空间“内"查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用mongomapper进行内部"查询.当我在shell中执行命令时,一切正常:
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
但是,当我在Rails控制台中运行相同代码时,却显示为nil:
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
如果我执行Location.first,我将获得一个位置,因此我知道我指向的是正确的数据库集合.我的mongomapper查询返回0个结果怎么办?
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?
推荐答案
嗯,我知道了.我没有使用查找",而是使用了"where".现在,我又得到了正确的结果.
Ah, I figured it out. Instead of using 'find' I used 'where' instead. Now I'm getting the correct result set back.
这篇关于mongomapper地理空间“内"查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!