【发布时间】:2017-02-10 05:55:13
【问题描述】:
我有一个 Node.js 测试,其中多个对象模拟从地图中的某个点移开,并且我不断测试它们是否在该点的半径范围内。
每个对象对应一个具有嵌套旧版二维索引 'location.loc' 的模型。
我用过这个查询
var center={_lat:20,lng:-100};
var area = {
center: [center._lng,center._lat],
radius: 100,//This are supossed to be meters
unique: true,
spherical: true }
MyModel.where('location.loc')
.within()
.circle(area)
.exec(function (err, records) {
if (err) {
throw err;
}
//Log Length of records
});
和
MyModel.find({
"location.loc": {
$near: [center._lng,center._lat],
$maxDistance: 1 //This is suposed to be a mile
}
}).exec(function(err, documents) {
if (err) {
throw err;
}
//Log documents length
});
但是这两个脚本都返回给我整个文档集合,即使它们距离该点数英里。 同时,我在我的 Mongo 客户端中使用 $near,$geoWithin 进行相同的查询,这些查询给了我正确的答案。
我的 Mongoose 脚本有什么问题?
对于这种情况,是否应该只使用within().circle()?
【问题讨论】:
标签: node.js mongodb mongoose geospatial