MongoDB supports the GeoJSON format for storing geographic coordinates and shapes. GeoJSON uses longitude first, latitude second — the opposite of most mapping UIs which show lat/lng. This is the most common source of bugs in geospatial code.
[-74.006, 40.7128] (lng, lat), not [40.7128, -74.006].// GeoJSON Point — a single location { type: "Point", coordinates: [-74.006, 40.7128] // [longitude, latitude] } // GeoJSON LineString — an ordered sequence of positions (a path) { type: "LineString", coordinates: [ [-74.006, 40.7128], // New York [-87.6298, 41.8781], // Chicago [-118.243, 34.0522] // Los Angeles ] } // GeoJSON Polygon — closed ring; first and last point must be identical { type: "Polygon", coordinates: [[ [-74.1, 40.6], [-73.9, 40.6], [-73.9, 40.8], [-74.1, 40.8], [-74.1, 40.6] // closes the ring (= first point) ]] } // Polygon with a hole (outer ring + inner ring as hole) { type: "Polygon", coordinates: [ [[-74.1, 40.6], [-73.9, 40.6], [-73.9, 40.8], [-74.1, 40.8], [-74.1, 40.6]], // outer [[-74.05, 40.65], [-73.95, 40.65], [-73.95, 40.75], [-74.05, 40.75], [-74.05, 40.65]] // hole ] } // MultiPoint, MultiLineString, MultiPolygon — arrays of the above // GeometryCollection — mixed types array // Storing a place with GeoJSON location: db.places.insertOne({ name: "Central Park", category: "park", location: { type: "Point", coordinates: [-73.9654, 40.7829] // [lng, lat] }, borough: "Manhattan" })