()内猫鼬。圆()和$附近给出的结果不同,以蒙戈查询
我在至极多个对象的Node.js试验模拟从某一点移开地图中,如果从该点radious内当当林countinuously测试。每个对象对应于与嵌套传统2D指数'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
});
但是,这两个脚本返回我的文档TE整个集合,甚至当他们英里从点之遥。同时,即时通讯做我蒙戈客户端$接近相同的查询,$ geoWithin和这些查询给了我正确的答案。
有什么不对我的猫鼬脚本?
应该只thest与内()。圆()对于这种情况?
回答如下:转出,在第一码半径被错误定义。在这种Mongo documentation说
随着球形:真,如果指定了以GeoJSON点,MongoDB使用米作为测量单位
但是,这是一个以GeoJSON点和geoNear
。
对于传统坐标格式[长,纬度],我们必须3963.2鸿沟英里半径值强制转换为弧度。看到这个Example。