2017-04-03 120 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有关更新的更多信息。