Geospatial features in MongoDB
Geospatial features in MongoDB are designed to support the creation of location-aware applications and facilitate location-based queries, catering to a diverse range of users. Through its specialized indexes and operators, MongoDB can efficiently manage geographical data, which makes it suitable for a wide range of applications, such as maps and location searching.
Legacy coordinate pairs are the traditional way of representing locations using two-element arrays with the longitude first and then the latitude. For example, [ -73.97, 40.77 ]
represents a point in New York City. When indexing such data, you can use the 2d
index type. Following is an example of creating index for legacy coordinate pairs:
db.collection.createIndex({ loc: "2d" })
GeoJSON objects
GeoJSON objects are of three types:
Point
: Represents a single point in space with longitude and latitude coordinatesLineString
: A series of two or more points that...