【发布时间】:2012-05-14 21:49:40
【问题描述】:
简单的问题:
在nodejs上使用猫鼬进行地理空间查询的正确方法是什么?
复杂的故事:
我用带有空间索引的猫鼬创建了一个模式
var MySchema = newSchema({
// skipped ...
location : {
type : [ Number ],
required : true,
index : '2d'
},
// skipped ...
});
然后我在表中插入了3个文件。
我可以使用 mongo 客户端和 mongoose 检索这些文档
使用db.mymodels.find({}) 和MyModel.find({});
现在我尝试使用边界框进行地理空间查询。
mongo 客户端工作正常
db.mymodels.find({location: {$within: {$box: box}}})
在框中只返回一个结果。
另一方面,Mongoose 返回所有三个结果
query = MyModel.where({location: {$within : {$box : box}}});
query.run(cb)
This question 说你应该使用 find() 而不是 where,
但是当我尝试用 where 替换 find 时,出现错误 'need an area > 0'
我检查了,我的边界框格式正确,左下角然后右上角。
怎么办? 使用 mongoose 使用边界框进行地理空间查询的正确方法是什么?
【问题讨论】:
-
您生成的查询是什么样的?
-
@SergioTulentsev 如何打印生成的查询?
-
啊,我以为你在使用 Rails。用节点,我不知道:)
标签: mongodb geospatial mongoose bounding-box mongodb-query