mongomapper地理空间“内”查询

问题描述 投票:1回答:1

我正在尝试使用mongomapper进行“内部”查询。 当我在shell中执行命令时,一切正常:

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

但是,当我在rails控制台中运行相同命令时,结果为nil:

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

如果我执行Location.first,我将获得一个位置,因此我知道我指向的是正确的数据库集合。 我的mongomapper查询返回0个结果怎么办?

mongodb geospatial mongomapper
1个回答
1
投票

啊,我知道了。 我没有使用“查找”,而是使用了“ where”。 现在,我得到了正确的结果集。

© www.soinside.com 2019 - 2024. All rights reserved.