Below is the document example saved in MongoDB, I saved polygon data as LNG & lat as mentioned in //https://www.mongodb.com/docs/manual/geospatial-queries/. I want to find the list of documents in which the given point is inside the polygon. eg: lang: -118.421871, lat: 33.943645.
the index is created for zones.area.geo.
I tried the solution mentioned in Mongolink. but data not coming, I am new to mongo, so any help is appreciated.
{
"zoneType": "GEO_FENCE",
"zones": [
{
"id": "5b9ddf55-d45e-4358-8f37-8fddb7d424e8",
"name": "Los Angeles, CA 90045, United States",
"area": {
"geo": {
"coordinates": [
[
[
-118.427456,
33.945997
],
[
-118.418435,
33.946995
],
[
-118.417232,
33.938442
],
[
-118.426425,
33.945997
],
[
-118.427456,
33.945997
]
]
],
"type": "Polygon"
}
}
}
]
}
below is the aggregation query I used to check point is inside the polygon or not.
[
{
'$match': {
'$and': [
{
'companyId': {
'$in': [
new ObjectId('63368dbb50f6df4a67f08695'), '63368dbb50f6df4a67f08695'
]
}
}, {
'$or': [
{
'zones.area.geo': {
'$geoIntersects': {
'$geometry': {
'type': 'Point',
'coordinates': [
-118.426253, 33.945641
]
}
}
}
}
]
}
]
}
}
]
please guide me to get this done. Thank you