MongoDB Tutorial 0/120 lessons ~6 min read Lesson 57

    Geospatial Queries

    MongoDB has first-class geospatial support — store GeoJSON points/polygons, index with 2dsphere, query with $near, $geoWithin, $geoIntersects.

    Course progress0%
    Focus
    3 guided sections
    Practice signal
    Concept-first lesson
    Career prep
    Foundation builder

    Introduction

    MongoDB has first-class geospatial support — store GeoJSON points/polygons, index with 2dsphere, query with $near, $geoWithin, $geoIntersects.

    Syntax reference

    js
    db.places.createIndex({ location: "2dsphere" });
    db.places.find({
    location: { $near: { $geometry: { type: "Point", coordinates: [-73.97, 40.77] }, $maxDistance: 1000 } }
    });

    Real-world use

    Used in Uber, food-delivery and dating apps for nearby search.

    Ready to mark this lesson complete?Track your journey across the entire course.