2017-04-03 62 views
0

我有很多的麻煩,下面蒙戈查詢

location: { $geoWithin: { $centerSphere: [[lon,lat],radians] } } 

它只返回GeoJSON的點,而忽略由於某種原因,我所有的GeoJSON的多邊形任何GeoJSON的多邊形(MongoDB的)。 documentation指出:

您可以在GeoJSON對象和傳統座標對上使用$ centerSphere運算符。

我使用Mongoose來運行查詢,我的g​​eoJSON是由NPM模塊wellknown從WellKnown Text轉換而來的。這是我的GeoJSON的外觀的知名模塊轉換後他們:

"location": { 
    "coordinates": [ 
     22.1, 
     33.3 
    ], 
    "type": "Point" 
} 

"location": { 
    "coordinates": [ 
     [ 
      [ 
       43, 
       30 
      ], 
      [ 
       40, 
       28 
      ], 
      [ 
       49, 
       27 
      ], 
      [ 
       43, 
       30 
      ] 
     ], 
     [ 
      [ 
       44, 
       28 
      ], 
      [ 
       44.7, 
       28.8 
      ], 
      [ 
       46, 
       28 
      ], 
      [ 
       44, 
       28 
      ] 
     ] 
    ], 
    "type": "Polygon" 
} 

我的貓鼬模式被定義爲:

location: { 
    type: schema.Types.Mixed, 
    index: '2dsphere', 
    required: false 
} 

我要補充的是,withinPolygon方法像預期的那樣工作,並且我得到了返回的點和多邊形。以下作品完全沒問題:

location: { $geoWithin: { $geometry: geoJSON } } 

謝謝你的幫助。我已經閱讀了文檔,並且無法看到它提到$ centerSphere只返回geoJSON點的地方。

回答

1

隨着最近的MongoDB版本3.6.0-RC0釋放,你現在可以查詢GeoJSON的路線]和多邊形與$geoWithin地理空間操作$centerSphere

另請參閱SERVER-27968有關更新的更多信息。