2017-02-22 53 views
0

我有一个集合的“机器”与文档

 

    { 
     "_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个不同的版本(查询中唯一区别在于近地点在近地点管线段

查询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返回我的文档,并提供了这个文件是5.88161133560063e-05公里,距搜索坐标

查询2将文件返回给我,并规定此文件距离搜索坐标375毫米距离公里(公里)

I交叉验证之间的这些LNG/LAT在网站上http://andrew.hedges.name/experiments/haversine/并看到该文档与搜索坐标之间的距离大约为374.835公里

看来查询2是提供正确的结果,但距离我不确定查询1和查询2之间有什么区别,以及我是否错误地使用它。

请告知

回答