2017-02-22 59 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之間有什麼區別,以及我是否錯誤地使用它。

請告知

回答