MongoDB $geoNear 操作 "near" 字段使用

MongoDB $geoNear operation "near" field usage

我有一个集合 "machine" 和文档


    {
        "_id" : "ac9d1db9-6a0d-47c6-97d3-a613c8dd0031",
        "pin" : {
            "machine":"test1",
            "position" : [ 
                -1.5716, 
                54.7732
            ]
        }
    }

Note: -1.5716 is lng and 54.7732 is lat

我在文档上创建了一个 2dsphere 索引


    db.machine.createIndex( { 'pin.position' : "2dsphere" } )

我尝试使用 2 个不同版本的查询(查询的唯一区别是 geoNear 管道阶段的近场

查询 1:


    db.machine.aggregate(
      [
       {
           "$geoNear":{
               "near": [-0.2129092,51.5031594],
               "limit":100,
               "maxDistance":500*1000,
               "distanceField": "dist.calculated",
               "includeLocs": "dist.location",
               "distanceMultiplier":1/1000,
               "spherical": true
        }

       }
      ]
    )

Note: -0.2129092 is lng and 51.5031594 is lat

查询 2


    db.machine.aggregate(
      [
       {
           "$geoNear":{
               "near": { type: "Point", coordinates: [-0.2129092,51.5031594] },
               "limit":100,
               "maxDistance":500*1000,
               "distanceField": "dist.calculated",
               "includeLocs": "dist.location",
               "distanceMultiplier":1/1000,
               "spherical": true
        }

       }
      ]
    )

Note: -0.2129092 is lng and 51.5031594 is lat

查询1 returns我的文档并提供这个文档距离搜索坐标5.88161133560063e-05 Kms

查询2 returns我的文档,并提供这个文档距离搜索坐标375.135052595944公里

我在网站 http://andrew.hedges.name/experiments/haversine/ 上交叉验证了这些 lng/lat 之间的距离,发现文档与搜索坐标之间的距离约为 374.835 公里

似乎查询 2 提供了正确的结果,但我不确定查询 1 和查询 2 之间的区别是什么,以及我是否使用不正确。

请指教

查询 1 提供传统坐标对中的距离,查询 2 提供以米 (GeoJSON) 为单位的距离,因此两个查询使用不同的单位

请检查以下内容linkhttps://jira.mongodb.org/browse/SERVER-16652?jql=text%20~%20%22geoNear%22