GeoJSON Objects
On this page
Overview
MongoDB supports the GeoJSON object types listed on this page.
To specify GeoJSON data, use an embedded document with:
a field named
type
that specifies the GeoJSON object type anda field named
coordinates
that specifies the object’s coordinates.If specifying latitude and longitude coordinates, list the longitude first and then latitude:
- Valid longitude values are between
-180
and180
, both inclusive. - Valid latitude values are between
-90
and90
, both inclusive.
- Valid longitude values are between
MongoDB geospatial queries on GeoJSON objects calculate on a sphere; MongoDB uses the WGS84 reference system for geospatial queries on GeoJSON objects.
Point
The following example specifies a GeoJSON Point :
LineString
The following example specifies a GeoJSON LineString :
Polygon
Polygons consist of an array of GeoJSON LinearRing
coordinate arrays. These LinearRings
are closed LineStrings
. Closed LineStrings
have at least four coordinate pairs and specify the same position as the first and last coordinates.
The line that joins two points on a curved surface may or may not contain the same set of co-ordinates that joins those two points on a flat surface. The line that joins two points on a curved surface will be a geodesic. Carefully check points to avoid errors with shared edges, as well as overlaps and other types of intersections.
Polygons with a Single Ring
The following example specifies a GeoJSON Polygon
with an exterior ring and no interior rings (or holes). The first and last coordinates must match in order to close the polygon:
For Polygons with a single ring, the ring cannot self-intersect.
Polygons with Multiple Rings
For Polygons with multiple rings:
- The first described ring must be the exterior ring.
- The exterior ring cannot self-intersect.
- Any interior ring must be entirely contained by the outer ring.
- Interior rings cannot intersect or overlap each other. Interior rings cannot share an edge.
The following example represents a GeoJSON polygon with an interior ring:
MultiPoint
New in version 2.6: Requires Versions
GeoJSON MultiPoint embedded documents encode a list of points.
MultiLineString
New in version 2.6: Requires Versions
The following example specifies a GeoJSON MultiLineString :
MultiPolygon
New in version 2.6: Requires Versions
The following example specifies a GeoJSON MultiPolygon :
GeometryCollection
New in version 2.6: Requires Versions
The following example stores coordinates of GeoJSON type GeometryCollection :