$geoIntersects
The $geoIntersects operator in Amazon DocumentDB is used to find documents whose geospatial data intersects with a specified GeoJSON object. This operator is useful for applications that require identifying documents based on their spatial relationship with a given geographic shape, such as a polygon or multipolygon.
Parameters
-
$geometry: A GeoJSON object that represents the shape to check for intersection. The supported GeoJSON object types arePoint,LineString,Polygon, andMultiPolygon.
Example (MongoDB Shell)
The following example demonstrates how to use the $geoIntersects operator to find the state name for a given set of coordinates in Amazon DocumentDB.
Create sample documents
db.states.insertMany([ { "name": "New York", "loc": { "type": "Polygon", "coordinates": [[ [-74.25909423828125, 40.47556838210948], [-73.70819091796875, 40.47556838210948], [-73.70819091796875, 41.31342607582222], [-74.25909423828125, 41.31342607582222], [-74.25909423828125, 40.47556838210948] ]] } }, { "name": "California", "loc": { "type": "Polygon", "coordinates": [[ [-124.4091796875, 32.56456771381587], [-114.5458984375, 32.56456771381587], [-114.5458984375, 42.00964153424558], [-124.4091796875, 42.00964153424558], [-124.4091796875, 32.56456771381587] ]] } } ]);
Query example
var location = [-73.965355, 40.782865]; db.states.find({ "loc": { "$geoIntersects": { "$geometry": { "type": "Point", "coordinates": location } } } }, { "name": 1 });
Output
{ "_id" : ObjectId("536b0a143004b15885c91a2c"), "name" : "New York" }
Code examples
To view a code example for using the $geoIntersects command, choose the tab for the language that you want to use: