$ geoIntersects不返回任何结果

时间:2017-01-05 15:52:55

标签: mongodb geospatial

我正在查询一个多边形,检查一个点是否在其中,但是没有返回结果。我在mongo shell中:( MongoDB shell版本:3.2.6)

db.restPolygons.find();
{
  "_id" : ObjectId("586e663175c32828be59e3a9"),
  "zoneCoordinates" : {
    "type" : "Polygon",
    "coordinates" : [
      [ 2, 0 ],
      [ 6, 0 ],
      [ 6, 2 ],
      [ 2, 2 ],
      [ 2, 0 ]
    ]
  }
}

db.restPolygons.find({
  "zoneCoordinates": {
    "$geoIntersects": {
      "$geometry": {
        "type": "Point",
        "coordinates": [3 ,1]
      }
    }
  }
}).count();
    0

1 个答案:

答案 0 :(得分:2)

您的多边形无效,它在START TRANSACTION; /* open the console and do /etc/init.d/postgrsql reload or equivalent for your system */ INSERT INTO my_table(id,name) value(1,'1'); COMMIT; 字段中缺少一层封闭数组。这应该工作:

coordinates

您可以在GeoJSONList

中检查GeoJSON对象的有效性