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

$geoIntersects

On this page

Definition

$geoIntersects

New in version 2.4.

Selects documents whose geospatial data intersects with a specified GeoJSON object; i.e. where the intersection of the data and the specified object is non-empty. This includes cases where the data and the specified object share an edge. $geoIntersects uses spherical geometry.

$geoIntersects does not require a geospatial index. However, a geospatial index will improve query performance. Only the 2dsphere geospatial index supports $geoIntersects.

The $geoIntersects operator uses the $geometry operator to specify the GeoJSON object and has the following form:

{
   <location field>: {
     $geoIntersects: {
        $geometry: {
          type: "<GeoJSON object type>" ,
          coordinates: [ <coordinates> ]
        }
     }
   }
}

Important

If you use longitude and latitude, specify coordinates in order of: longitude, latitude.

Behavior

For $geoIntersects queries, GeoJSON geometries must have an area less than the area of a single hemisphere. For geometries larger than a single hemisphere, MongoDB queries for the smaller of the complementary geometries. For geometries equal to a single hemisphere, MongoDB makes no guarantees as to which geometry (the specified geometry or the complementary) it uses.

Example

The following example uses $geoIntersects to select all loc data 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 ] ]
             ]
          }
       }
     }
   }
)
←   $geoWithin $near  →