Reputation: 663
I have a list of polygons stored as geoJson inside MongoDB. Example of one of the polygons: { "Area" : "Area123", "Boundary" : { "type" : "Polygon", "coordinates" : [[[100,12],[120,12],[120,15],[100,12]]] } } Boundary is a 2dsphere index.
Using $geoWithin, I am able to specify a bigger polygon and return Area123 which lies fully within this bigger polygon.
Is there a way to specify a smaller polygon that lies within Area123 and let MongoDB returns Area123?
Upvotes: 0
Views: 253
Reputation: 3501
You can use $geoIntersects who specifically looks for polygon intersecting other ones. You can do something like this:
db.<collection>.find( { Boundary :
{ $geoIntersects :
{ $geometry :
{ type : "Polygon"
coordinates : [ <coordinates of Area123> ]
} } } } )
However this query will return even polygons who doesn't contains Area123
but also those who are inside, those who intersect a bit, etc.
So you can check if Area123 points, for each returned Polygon, are contained inside.
Upvotes: 1