MongoDB 3.0.4 $ nearSphere $ maxDistance奇怪的行为

时间:2015-06-23 11:08:33

标签: mongodb

我对$ maxDistance中的距离测量有疑问。我有文件:

{
    "location": {
        { "type" : "Point", "coordinates" : [ 38.8993487, -77.0145665 ] }
    }
}

在shell中进行查询:

db.places.find({"location": {"$nearSphere": {"$geometry": {"type":"Point", "coordinates": [38.888684, -77.0047189]}, "$maxDistance": 1129 } }})[0].location

返回

{ "type" : "Point", "coordinates" : [ 38.8993487, -77.0145665 ] }

gpsvisualizer.com所做的距离测量显示我 1.4600 km 。 Mongo的结果是maxDistance设置为 1129 meters

所以我的问题是 - 我错过了什么?:D

1 个答案:

答案 0 :(得分:1)

我认为你错过了一个事实,即mongoDB的2d球形索引运算符只能识别[经度,纬度]排序。正确的链接是:gpsvisualiser。如你所见,这些点之间的差距约为1,13公里:)