MongoDB How to find which polygon contains a specified Point?

我是研究僧i 提交于 2019-12-05 13:08:37

Use the $geoIntersects operator. It queries for all shapes which intersect the GeoJSON object you pass. When you pass a point to it, it should return all shapes which include that point. Keep in mind that the $geoIntersects operator only works for 2dsphere indexes, not for 2d indexes.

As @philipp said, you should use the $geoIntesects operator. I was having the hardest time trying to figure out the query. I figured I would share what it looks and it might save someone the trouble later.

db.addr_poly.find({
    loc:{
        $geoIntersects: {
            $geometry: {
              type: "Point" ,
              coordinates: [1, 1]
            }
         }
     }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!