Navigation
This version of the documentation is archived and no longer supported.

$geoIntersects

$geoIntersects

New in version 2.4.

The $geoIntersects operator is a geospatial query operator that selects all locations that intersect with a GeoJSON object. A location intersects a GeoJSON object if the intersection is non-empty. This includes documents that have a shared edge. The $geoIntersects operator uses spherical geometry.

The 2dsphere geospatial index supports $geoIntersects.

To query for intersection, pass the GeoJSON object to $geoIntersects through the $geometry operator. Use the following syntax:

db.<collection>.find( { <location field> :
                         { $geoIntersects :
                            { $geometry :
                               { type : "<GeoJSON object type>" ,
                                 coordinates : [ <coordinates> ]
                      } } } } )

Important

Specify coordinates in this order: “longitude, latitude.”

The following example uses $geoIntersects to select all indexed points and shapes that intersect with the polygon defined by the coordinates array.

db.places.find( { loc :
                  { $geoIntersects :
                    { $geometry :
                      { type : "Polygon" ,
                        coordinates: [ [ [ 0 , 0 ] , [ 3 , 6 ] , [ 6 , 1 ] , [ 0 , 0 ] ] ]
                } } } } )

Note

Any geometry specified with GeoJSON to $geoIntersects queries, must fit within a single hemisphere. MongoDB interprets geometries larger than half of the sphere as queries for the smaller of the complementary geometries.

←   $geoWithin $near  →