在GeoJSON字段中使用纬度和经度在MongoDB中查找文档

时间:2019-06-09 03:52:12

标签: json mongodb geojson

我的MongoDB拥有代表餐厅和送货范围(GeoJSON)的文档:

{
    "id": "1010",
    "name": "Food In Box",
    "coverageArea": {
        "type": "MultiPolygon",
        "coordinates": [
            [
                [
                    [-46.70103, -23.61731],
                    [-46.72086, -23.63517],
                    [-46.7357, -23.62738 ],
                    [-46.74618, -23.60575],
                    [-46.7557, -23.60855],
                    [-46.76999, -23.5987],
                    [-46.7721, -23.58224],
                    [-46.76326, -23.57079],
                    [-46.73433, -23.54613],
                    [-46.70644, -23.56163],
                    [-46.70335, -23.56973],
                    [-46.69073, -23.58475],
                    [-46.70103, -23.61731]
                ]
            ]
        ]
    },
    "address": {
        "type": "Point",
        "coordinates": [
            -46.720875,
            -23.584986
        ]
    }
}

我有一个Point(lng,lat),需要检查此位置是否在餐厅的覆盖范围内。 我已经尝试使用$ geoIntersects和$ geoWithin查询,但是不起作用:

db.places.find({coverageArea: {$geoIntersects: {$geometry: {type : "Point",coordinates: [-22.989901, -43.380630]}}}})

您有什么建议吗?

0 个答案:

没有答案