GeoJSON objects are needed in order to conduct geospatial queries involving a spherical model. These object types are modeled after RFC 7946, The GeoJSON Format, published in August 2016. Here is the generic syntax for creating a MongoDB GeoJSON object:
<field>: { type: <GeoJSON type> , coordinates: <coordinates> }
Please note that, depending on the GeoJSON object type, there may be more than one pair of coordinates. MongoDB supports a number of these objects, summarized here:
- Point:
- Definition: A distinct location represented by two coordinates on an imaginary X-Y grid.
- Syntax:
<field>: { type: "Point", coordinates: [ x, y ] }
- LineString:
- Definition: A set of points in a straight line starting at x1,y1 and ending at x2,y2.
- Syntax:
<field>: { type: "LineString", coordinates: [[x1,y1], [x2,y2]] }
- Polygon:
- Definition: An array of GeoJSON LinearRing coordinate arrays. LinearRing arrays are LineString...