<section>
 <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
  Geospatial Queries
  <a class="headerlink leafygreen-ui-1kepx47" href="#geospatial-queries" title="Permalink to this heading">
   <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
    <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
    </path>
    <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
    </path>
   </svg>
   <div class="css-1btu0w3 evvkmar0" id="geospatial-queries">
   </div>
  </a>
 </h1>
 <div class="leafygreen-ui-a5yxub">
  <p class="css-1cmx2d4 ef7gu8j0">
   On this page
  </p>
  <ul class="css-1qb0mst ef7gu8j1">
   <li class="leafygreen-ui-1e7a0ei">
    <a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#compatibility" target="_self">
     <span>
      Compatibility
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#geospatial-data" target="_self">
     <span>
      Geospatial Data
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#geospatial-indexes" target="_self">
     <span>
      Geospatial Indexes
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#geospatial-queries-1" target="_self">
     <span>
      Geospatial Queries
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#geospatial-models" target="_self">
     <span>
      Geospatial Models
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#perform-geospatial-queries-in-atlas" target="_self">
     <span>
      Perform Geospatial Queries in Atlas
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self">
     <span>
      Examples
     </span>
    </a>
   </li>
  </ul>
 </div>
 <p class="leafygreen-ui-1kp3ins">
  MongoDB supports query operations on geospatial data. This section
introduces MongoDB's geospatial features.
 </p>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Compatibility
   <a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" title="Permalink to this heading">
    <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
     <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
     </path>
     <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
     </path>
    </svg>
    <div class="css-1btu0w3 evvkmar0" id="compatibility">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   You can use
   <!-- -->
   geospatial queries
   <!-- -->
   for deployments hosted in the following
environments:
  </p>
  <ul class="leafygreen-ui-rioki0">
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas?tck=docs_server" target="_self">
      <span>
       MongoDB Atlas
      </span>
     </a>
     : The fully
managed service for MongoDB deployments in the cloud
    </p>
   </li>
  </ul>
  <ul class="leafygreen-ui-rioki0">
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-enterprise/#std-label-install-mdb-enterprise">
      MongoDB Enterprise
     </a>
     : The
subscription-based, self-managed version of MongoDB
    </p>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-community/#std-label-install-mdb-community-edition">
      MongoDB Community
     </a>
     : The
source-available, free-to-use, and self-managed version of MongoDB
    </p>
   </li>
  </ul>
  <p class="leafygreen-ui-1kp3ins">
   For deployments hosted in MongoDB Atlas, you can run geospatial
queries in the UI by using the query
   <span class="guilabel css-h15tq0">
    Filter
   </span>
   bar or aggregation
builder. To learn more, see
   <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geospatial-queries-atlas" target="_self">
    <span>
     Perform Geospatial Queries in Atlas
     <!-- -->
     .
    </span>
   </a>
  </p>
  <span class="leafygreen-ui-1qnjd6d" id="std-label-geo-overview-location-data">
  </span>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Geospatial Data
   <a class="headerlink leafygreen-ui-1kepx47" href="#geospatial-data" title="Permalink to this heading">
    <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
     <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
     </path>
     <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
     </path>
    </svg>
    <div class="css-1btu0w3 evvkmar0" id="geospatial-data">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   In MongoDB, you can store geospatial data as
   <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geospatial-geojson" target="_self">
    <span>
     GeoJSON
    </span>
   </a>
   objects or as
   <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geospatial-legacy" target="_self">
    <span>
     legacy coordinate pairs
     <!-- -->
     .
    </span>
   </a>
  </p>
  <span class="leafygreen-ui-1qnjd6d" id="std-label-geospatial-geojson">
  </span>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    GeoJSON Objects
    <a class="headerlink leafygreen-ui-1kepx47" href="#geojson-objects" title="Permalink to this heading">
     <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
      <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
      </path>
      <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
      </path>
     </svg>
     <div class="css-1btu0w3 evvkmar0" id="geojson-objects">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    To calculate geometry over an Earth-like sphere, store your location
data as
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/geojson/#std-label-geospatial-indexes-store-geojson">
     GeoJSON objects
     <!-- -->
     .
    </a>
   </p>
   <p class="leafygreen-ui-1kp3ins">
    To specify GeoJSON data, use an embedded document with:
   </p>
   <ul class="leafygreen-ui-rioki0">
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      a field named
      <code class="leafygreen-ui-1l06pbn">
       type
      </code>
      that specifies the GeoJSON object
type, and
     </p>
    </li>
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      a field named
      <code class="leafygreen-ui-1l06pbn">
       coordinates
      </code>
      that specifies the object's
coordinates.
     </p>
    </li>
   </ul>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"&lt;field&gt;: { type: &lt;geojson&gt; , coordinates: &lt;coordinates&gt; }","programmingLanguage":"JavaScript"}
   </script>
   <div class="css-16lmvu9">
    <div class="leafygreen-ui-196mwvg">
     <div class="leafygreen-ui-1b1bvay">
      <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">&lt;<!-- -->field<!-- -->&gt;<!-- -->: <!-- -->{ <span class="lg-highlight-attr">type</span>: <!-- -->&lt;GeoJSON type&gt; , coordinates: &lt;coordinates&gt; }</td></tr></tbody></table></code></pre>
      <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
       <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
        <div class="leafygreen-ui-xhlipt">
         <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
          <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
          </path>
         </svg>
        </div>
       </button>
      </div>
     </div>
    </div>
   </div>
   <div class="leafygreen-ui-85da11" role="note">
    <h2 class="leafygreen-ui-1ac4g5h">
     Important
    </h2>
    <div class="leafygreen-ui-9mycqc">
     <p class="leafygreen-ui-1kp3ins">
      If specifying latitude and longitude coordinates, list the
      <strong>
       longitude
      </strong>
      first, and then
      <strong>
       latitude
      </strong>
      .
     </p>
     <ul class="leafygreen-ui-rioki0">
      <li class="leafygreen-ui-d7p7b6">
       <p class="leafygreen-ui-1kp3ins">
        Valid longitude values are between
        <code class="leafygreen-ui-1l06pbn">
         -180
        </code>
        and
        <code class="leafygreen-ui-1l06pbn">
         180
        </code>
        , both
inclusive.
       </p>
      </li>
      <li class="leafygreen-ui-d7p7b6">
       <p class="leafygreen-ui-1kp3ins">
        Valid latitude values are between
        <code class="leafygreen-ui-1l06pbn">
         -90
        </code>
        and
        <code class="leafygreen-ui-1l06pbn">
         90
        </code>
        , both
inclusive.
       </p>
      </li>
     </ul>
    </div>
   </div>
   <p class="leafygreen-ui-1kp3ins">
    For example, to specify a
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/geojson/#std-label-geojson-point">
     GeoJSON Point
     <!-- -->
     :
    </a>
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"location: {\n      type: \"Point\",\n      coordinates: [-73.856077, 40.848447]\n}","programmingLanguage":"JavaScript"}
   </script>
   <div class="css-16lmvu9">
    <div class="leafygreen-ui-196mwvg">
     <div class="leafygreen-ui-yzcs8i">
      <pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">location</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"Point"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">coordinates</span>: <!-- -->[<!-- -->-<span class="lg-highlight-number">73.856077</span>, <span class="lg-highlight-number">40.848447</span>]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
      <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
       <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
        <div class="leafygreen-ui-xhlipt">
         <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
          <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
          </path>
         </svg>
        </div>
       </button>
      </div>
     </div>
    </div>
   </div>
   <p class="leafygreen-ui-1kp3ins">
    For a list of the GeoJSON objects supported in MongoDB as well as
examples, see
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/geojson/#std-label-geospatial-indexes-store-geojson">
     GeoJSON objects
     <!-- -->
     .
    </a>
   </p>
   <p class="leafygreen-ui-1kp3ins">
    MongoDB geospatial queries on GeoJSON objects calculate on a sphere;
MongoDB uses the
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-WGS84">
     WGS84
    </a>
    reference system for geospatial
queries on GeoJSON objects.
   </p>
   <span class="leafygreen-ui-1qnjd6d" id="std-label-geospatial-legacy">
   </span>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Legacy Coordinate Pairs
    <a class="headerlink leafygreen-ui-1kepx47" href="#legacy-coordinate-pairs" title="Permalink to this heading">
     <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
      <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
      </path>
      <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
      </path>
     </svg>
     <div class="css-1btu0w3 evvkmar0" id="legacy-coordinate-pairs">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    To calculate distances on a Euclidean plane, store your location data
as legacy coordinate pairs and use a
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geo-2d" target="_self">
     <span>
      <code class="leafygreen-ui-1l06pbn">
       2d
      </code>
     </span>
    </a>
    index. MongoDB
supports spherical surface calculations on legacy coordinate pairs by using
a
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geo-2dsphere" target="_self">
     <span>
      <code class="leafygreen-ui-1l06pbn">
       2dsphere
      </code>
     </span>
    </a>
    index if you manually convert the data to
the
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/geojson/#std-label-geojson-point">
     GeoJSON Point type
     <!-- -->
     .
    </a>
   </p>
   <p class="leafygreen-ui-1kp3ins">
    To specify data as legacy coordinate pairs, you can use either an
array (
    <em>
     preferred
    </em>
    ) or an embedded document.
   </p>
   <dl>
    <dt>
     Specify via an array (
     <em>
      Preferred
     </em>
     ):
    </dt>
    <dd class="css-1ufxuu7">
     <script class="structured_data" type="application/ld+json">
      {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"&lt;field&gt;: [ &lt;x&gt;, &lt;y&gt; ]","programmingLanguage":"JavaScript"}
     </script>
     <div class="css-16lmvu9">
      <div class="leafygreen-ui-196mwvg">
       <div class="leafygreen-ui-yzcs8i">
        <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">&lt;<!-- -->field<!-- -->&gt;<!-- -->: <!-- -->[ &lt;<!-- -->x<!-- -->&gt;<!-- -->,<!-- --> <!-- -->&lt;<!-- -->y<!-- -->&gt; <!-- -->]</td></tr></tbody></table></code></pre>
        <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
         <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
          <div class="leafygreen-ui-xhlipt">
           <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
            <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
            </path>
           </svg>
          </div>
         </button>
        </div>
       </div>
      </div>
     </div>
     <p class="leafygreen-ui-1kp3ins">
      If specifying latitude and longitude coordinates, list the
      <strong>
       longitude
      </strong>
      first and then
      <strong>
       latitude
      </strong>
      ; i.e.
     </p>
     <script class="structured_data" type="application/ld+json">
      {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"&lt;field&gt;: [&lt;longitude&gt;, &lt;latitude&gt; ]","programmingLanguage":"JavaScript"}
     </script>
     <div class="css-16lmvu9">
      <div class="leafygreen-ui-196mwvg">
       <div class="leafygreen-ui-yzcs8i">
        <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">&lt;<!-- -->field<!-- -->&gt;<!-- -->: <!-- -->[&lt;<!-- -->longitude<!-- -->&gt;<!-- -->,<!-- --> <!-- -->&lt;<!-- -->latitude<!-- -->&gt; <!-- -->]</td></tr></tbody></table></code></pre>
        <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
         <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
          <div class="leafygreen-ui-xhlipt">
           <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
            <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
            </path>
           </svg>
          </div>
         </button>
        </div>
       </div>
      </div>
     </div>
     <ul class="leafygreen-ui-rioki0">
      <li class="leafygreen-ui-d7p7b6">
       <p class="leafygreen-ui-1kp3ins">
        Valid longitude values are between
        <code class="leafygreen-ui-1l06pbn">
         -180
        </code>
        and
        <code class="leafygreen-ui-1l06pbn">
         180
        </code>
        , both
inclusive.
       </p>
      </li>
      <li class="leafygreen-ui-d7p7b6">
       <p class="leafygreen-ui-1kp3ins">
        Valid latitude values are between
        <code class="leafygreen-ui-1l06pbn">
         -90
        </code>
        and
        <code class="leafygreen-ui-1l06pbn">
         90
        </code>
        , both
inclusive.
       </p>
      </li>
     </ul>
    </dd>
    <dt>
     Specify via an embedded document:
    </dt>
    <dd class="css-1ufxuu7">
     <script class="structured_data" type="application/ld+json">
      {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"&lt;field&gt;: { &lt;field1&gt;: &lt;x&gt;, &lt;field2&gt;: &lt;y&gt; }","programmingLanguage":"JavaScript"}
     </script>
     <div class="css-16lmvu9">
      <div class="leafygreen-ui-196mwvg">
       <div class="leafygreen-ui-yzcs8i">
        <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">&lt;<!-- -->field<!-- -->&gt;<!-- -->: <!-- -->{ &lt;<!-- -->field1<!-- -->&gt;<!-- -->: &lt;<!-- -->x<!-- -->&gt;<!-- -->,<!-- --> <!-- -->&lt;<!-- -->field2<!-- -->&gt;<!-- -->: &lt;<!-- -->y<!-- -->&gt; <!-- -->}</td></tr></tbody></table></code></pre>
        <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
         <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
          <div class="leafygreen-ui-xhlipt">
           <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
            <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
            </path>
           </svg>
          </div>
         </button>
        </div>
       </div>
      </div>
     </div>
     <p class="leafygreen-ui-1kp3ins">
      If specifying latitude and longitude coordinates, the first field,
regardless of the field name, must contain the
      <strong>
       longitude
      </strong>
      value
and the second field, the
      <strong>
       latitude
      </strong>
      value ; i.e.
     </p>
     <script class="structured_data" type="application/ld+json">
      {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"&lt;field&gt;: { &lt;field1&gt;: &lt;longitude&gt;, &lt;field2&gt;: &lt;latitude&gt; }","programmingLanguage":"JavaScript"}
     </script>
     <div class="css-16lmvu9">
      <div class="leafygreen-ui-196mwvg">
       <div class="leafygreen-ui-1b1bvay">
        <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">&lt;<!-- -->field<!-- -->&gt;<!-- -->: <!-- -->{ &lt;<!-- -->field1<!-- -->&gt;<!-- -->: &lt;<!-- -->longitude<!-- -->&gt;<!-- -->,<!-- --> <!-- -->&lt;<!-- -->field2<!-- -->&gt;<!-- -->: &lt;<!-- -->latitude<!-- -->&gt; <!-- -->}</td></tr></tbody></table></code></pre>
        <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
         <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
          <div class="leafygreen-ui-xhlipt">
           <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
            <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
            </path>
           </svg>
          </div>
         </button>
        </div>
       </div>
      </div>
     </div>
     <ul class="leafygreen-ui-rioki0">
      <li class="leafygreen-ui-d7p7b6">
       <p class="leafygreen-ui-1kp3ins">
        Valid longitude values are between
        <code class="leafygreen-ui-1l06pbn">
         -180
        </code>
        and
        <code class="leafygreen-ui-1l06pbn">
         180
        </code>
        , both
inclusive.
       </p>
      </li>
      <li class="leafygreen-ui-d7p7b6">
       <p class="leafygreen-ui-1kp3ins">
        Valid latitude values are between
        <code class="leafygreen-ui-1l06pbn">
         -90
        </code>
        and
        <code class="leafygreen-ui-1l06pbn">
         90
        </code>
        , both
inclusive.
       </p>
      </li>
     </ul>
    </dd>
   </dl>
   <p class="leafygreen-ui-1kp3ins">
    To specify legacy coordinate pairs, arrays are preferred over an
embedded document as some languages do not guarantee associative map
ordering.
   </p>
   <span class="leafygreen-ui-1qnjd6d" id="std-label-index-feature-geospatial">
   </span>
  </section>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Geospatial Indexes
   <a class="headerlink leafygreen-ui-1kepx47" href="#geospatial-indexes" title="Permalink to this heading">
    <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
     <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
     </path>
     <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
     </path>
    </svg>
    <div class="css-1btu0w3 evvkmar0" id="geospatial-indexes">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   MongoDB provides the following geospatial index types to support
geospatial queries. For more information on geospatial indexes, see
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-geospatial/#std-label-geospatial-index">
    Geospatial Indexes
    <!-- -->
    .
   </a>
  </p>
  <span class="leafygreen-ui-1qnjd6d" id="std-label-geo-2dsphere">
  </span>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    <code class="leafygreen-ui-1l06pbn">
     2dsphere
    </code>
    <a class="headerlink leafygreen-ui-1kepx47" href="#2dsphere" title="Permalink to this heading">
     <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
      <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
      </path>
      <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
      </path>
     </svg>
     <div class="css-1btu0w3 evvkmar0" id="2dsphere">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2dsphere/#std-label-2dsphere-index">
     2dsphere
    </a>
    indexes support queries that calculate
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geospatial-geometry" target="_self">
     <span>
      geometries on an earth-like sphere
      <!-- -->
      .
     </span>
    </a>
   </p>
   <p class="leafygreen-ui-1kp3ins">
    To create a
    <code class="leafygreen-ui-1l06pbn">
     2dsphere
    </code>
    index, use the
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.createIndex/#mongodb-method-db.collection.createIndex">
     <code class="leafygreen-ui-1l06pbn">
      db.collection.createIndex()
     </code>
    </a>
    method and specify the string
literal
    <code class="leafygreen-ui-1l06pbn">
     "2dsphere"
    </code>
    as the index type:
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.createIndex( { &lt;location&gt; : \"2dsphere\" } )","programmingLanguage":"JavaScript"}
   </script>
   <div class="css-16lmvu9">
    <div class="leafygreen-ui-196mwvg">
     <div class="leafygreen-ui-1b1bvay">
      <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">createIndex</span>( <!-- -->{ <span class="lg-highlight-tag lg-highlight-xml">&lt;</span><span class="lg-highlight-name lg-highlight-tag lg-highlight-xml">location</span><span class="lg-highlight-tag lg-highlight-xml"> </span><span class="lg-highlight-attr lg-highlight-tag lg-highlight-xml">field</span><span class="lg-highlight-tag lg-highlight-xml">&gt;</span><span class="lg-highlight-xml"> : "2dsphere" } )</span></td></tr></tbody></table></code></pre>
      <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
       <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
        <div class="leafygreen-ui-xhlipt">
         <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
          <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
          </path>
         </svg>
        </div>
       </button>
      </div>
     </div>
    </div>
   </div>
   <p class="leafygreen-ui-1kp3ins">
    where the
    <code class="leafygreen-ui-1l06pbn">
     &lt;location field&gt;
    </code>
    is a field whose value is either a
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geospatial-geojson" target="_self">
     <span>
      GeoJSON object
     </span>
    </a>
    or a
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geospatial-legacy" target="_self">
     <span>
      legacy
coordinates pair
      <!-- -->
      .
     </span>
    </a>
   </p>
   <div class="leafygreen-ui-15mdk4" role="note">
    <h2 class="leafygreen-ui-6n7b7d">
     Note
    </h2>
    <div class="leafygreen-ui-9mycqc">
     <p class="leafygreen-ui-1kp3ins">
      If you try to create an index on a field that contains an array of
geoJSON points, the index build fails and returns the following error:
     </p>
     <p class="leafygreen-ui-1kp3ins">
      <code class="leafygreen-ui-1l06pbn">
       MongoServerError: Index build failed
      </code>
     </p>
    </div>
   </div>
   <p class="leafygreen-ui-1kp3ins">
    For more information on the
    <code class="leafygreen-ui-1l06pbn">
     2dsphere
    </code>
    index, see
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2dsphere/#std-label-2dsphere-index">
     2dsphere Indexes
     <!-- -->
     .
    </a>
   </p>
   <span class="leafygreen-ui-1qnjd6d" id="std-label-geo-2d">
   </span>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    <code class="leafygreen-ui-1l06pbn">
     2d
    </code>
    <a class="headerlink leafygreen-ui-1kepx47" href="#2d" title="Permalink to this heading">
     <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
      <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
      </path>
      <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
      </path>
     </svg>
     <div class="css-1btu0w3 evvkmar0" id="2d">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2d/#std-label-2d-index">
     2d
    </a>
    indexes support queries that calculate
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geospatial-geometry" target="_self">
     <span>
      geometries on a two-dimensional plane
     </span>
    </a>
    .
Although the index can support
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/nearSphere/#mongodb-query-op.-nearSphere">
     <code class="leafygreen-ui-1l06pbn">
      $nearSphere
     </code>
    </a>
    queries that
calculate on a sphere, if possible, use the
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geo-2dsphere" target="_self">
     <span>
      <code class="leafygreen-ui-1l06pbn">
       2dsphere
      </code>
     </span>
    </a>
    index
for spherical queries.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    To create a
    <code class="leafygreen-ui-1l06pbn">
     2d
    </code>
    index, use the
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.createIndex/#mongodb-method-db.collection.createIndex">
     <code class="leafygreen-ui-1l06pbn">
      db.collection.createIndex()
     </code>
    </a>
    method, specifying the location field as the key and the string literal
    <code class="leafygreen-ui-1l06pbn">
     "2d"
    </code>
    as the index type:
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.createIndex( { &lt;location&gt; : \"2d\" } )","programmingLanguage":"JavaScript"}
   </script>
   <div class="css-16lmvu9">
    <div class="leafygreen-ui-196mwvg">
     <div class="leafygreen-ui-yzcs8i">
      <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">createIndex</span>( <!-- -->{ <span class="lg-highlight-tag lg-highlight-xml">&lt;</span><span class="lg-highlight-name lg-highlight-tag lg-highlight-xml">location</span><span class="lg-highlight-tag lg-highlight-xml"> </span><span class="lg-highlight-attr lg-highlight-tag lg-highlight-xml">field</span><span class="lg-highlight-tag lg-highlight-xml">&gt;</span><span class="lg-highlight-xml"> : "2d" } )</span></td></tr></tbody></table></code></pre>
      <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
       <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
        <div class="leafygreen-ui-xhlipt">
         <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
          <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
          </path>
         </svg>
        </div>
       </button>
      </div>
     </div>
    </div>
   </div>
   <p class="leafygreen-ui-1kp3ins">
    where the
    <code class="leafygreen-ui-1l06pbn">
     &lt;location field&gt;
    </code>
    is a field whose value is a
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geospatial-legacy" target="_self">
     <span>
      legacy
coordinates pair
      <!-- -->
      .
     </span>
    </a>
   </p>
   <p class="leafygreen-ui-1kp3ins">
    For more information on the
    <code class="leafygreen-ui-1l06pbn">
     2d
    </code>
    index, see
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2d/#std-label-2d-index">
     2d Indexes
     <!-- -->
     .
    </a>
   </p>
  </section>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Geospatial Queries
   <a class="headerlink leafygreen-ui-1kepx47" href="#geospatial-queries-1" title="Permalink to this heading">
    <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
     <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
     </path>
     <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
     </path>
    </svg>
    <div class="css-1btu0w3 evvkmar0" id="geospatial-queries-1">
    </div>
   </a>
  </h2>
  <div class="leafygreen-ui-15mdk4" role="note">
   <h2 class="leafygreen-ui-6n7b7d">
    Note
   </h2>
   <div class="leafygreen-ui-9mycqc">
    <p class="leafygreen-ui-1kp3ins">
     Using a
     <code class="leafygreen-ui-1l06pbn">
      2d
     </code>
     index for queries on spherical data
can return incorrect results or an error. For example,
     <code class="leafygreen-ui-1l06pbn">
      2d
     </code>
     indexes don't support spherical queries that wrap
around the poles.
    </p>
   </div>
  </div>
  <span class="leafygreen-ui-1qnjd6d" id="std-label-geospatial-operators">
  </span>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Geospatial Query Operators
    <a class="headerlink leafygreen-ui-1kepx47" href="#geospatial-query-operators" title="Permalink to this heading">
     <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
      <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
      </path>
      <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
      </path>
     </svg>
     <div class="css-1btu0w3 evvkmar0" id="geospatial-query-operators">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    MongoDB provides the following geospatial query operators. For more details, including examples, see the respective reference pages.
   </p>
   <div class="leafygreen-ui-skkc39" tabindex="0">
    <table class="leafygreen-ui-hr8lsv">
     <colgroup>
      <col style="width:30%"/>
      <col style="width:70%"/>
     </colgroup>
     <thead class="leafygreen-ui-a9ho40">
      <tr data-testid="leafygreen-ui-header-row">
       <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
        <div class="leafygreen-ui-ui0te9">
         <div>
          Name
         </div>
        </div>
       </th>
       <th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
        <div class="leafygreen-ui-ui0te9">
         <div>
          Description
         </div>
        </div>
       </th>
      </tr>
     </thead>
     <tbody>
      <tr class="">
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/geoIntersects/#mongodb-query-op.-geoIntersects">
           <code class="leafygreen-ui-1l06pbn">
            $geoIntersects
           </code>
          </a>
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          Selects geometries that intersect with a
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-GeoJSON">
           GeoJSON
          </a>
          geometry.
The
          <code class="leafygreen-ui-1l06pbn">
           2dsphere
          </code>
          index supports
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/geoIntersects/#mongodb-query-op.-geoIntersects">
           <code class="leafygreen-ui-1l06pbn">
            $geoIntersects
           </code>
           .
          </a>
         </div>
        </div>
       </td>
      </tr>
      <tr class="">
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/geoWithin/#mongodb-query-op.-geoWithin">
           <code class="leafygreen-ui-1l06pbn">
            $geoWithin
           </code>
          </a>
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          Selects geometries within a bounding
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/geojson/#std-label-geospatial-indexes-store-geojson">
           GeoJSON geometry
          </a>
          . The
          <code class="leafygreen-ui-1l06pbn">
           2dsphere
          </code>
          and
          <code class="leafygreen-ui-1l06pbn">
           2d
          </code>
          indexes support
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/geoWithin/#mongodb-query-op.-geoWithin">
           <code class="leafygreen-ui-1l06pbn">
            $geoWithin
           </code>
           .
          </a>
         </div>
        </div>
       </td>
      </tr>
      <tr class="">
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/near/#mongodb-query-op.-near">
           <code class="leafygreen-ui-1l06pbn">
            $near
           </code>
          </a>
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          Returns geospatial objects in proximity to a point.
Requires a geospatial index.  The
          <code class="leafygreen-ui-1l06pbn">
           2dsphere
          </code>
          and
          <code class="leafygreen-ui-1l06pbn">
           2d
          </code>
          indexes
support
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/near/#mongodb-query-op.-near">
           <code class="leafygreen-ui-1l06pbn">
            $near
           </code>
           .
          </a>
         </div>
        </div>
       </td>
      </tr>
      <tr class="">
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/nearSphere/#mongodb-query-op.-nearSphere">
           <code class="leafygreen-ui-1l06pbn">
            $nearSphere
           </code>
          </a>
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          Returns geospatial objects in proximity to a point on a sphere.
Requires a geospatial index.  The
          <code class="leafygreen-ui-1l06pbn">
           2dsphere
          </code>
          and
          <code class="leafygreen-ui-1l06pbn">
           2d
          </code>
          indexes
support
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/nearSphere/#mongodb-query-op.-nearSphere">
           <code class="leafygreen-ui-1l06pbn">
            $nearSphere
           </code>
           .
          </a>
         </div>
        </div>
       </td>
      </tr>
     </tbody>
    </table>
   </div>
   <div class="leafygreen-ui-15mdk4" role="note">
    <h2 class="leafygreen-ui-6n7b7d">
     Note
    </h2>
    <div class="leafygreen-ui-9mycqc">
     <p class="leafygreen-ui-1kp3ins">
      Time series collections only support the
      <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/geoNear/#mongodb-pipeline-pipe.-geoNear">
       <code class="leafygreen-ui-1l06pbn">
        $geoNear
       </code>
      </a>
      aggregation stage for sorting
      <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geospatial-queries" target="_self">
       <span>
        geospatial data
       </span>
      </a>
      from queries against
      <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/geospatial/2dsphere/#std-label-2dsphere-index">
       2dsphere
      </a>
      indexes. You can't use
      <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/near/#mongodb-query-op.-near">
       <code class="leafygreen-ui-1l06pbn">
        $near
       </code>
      </a>
      and
      <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/nearSphere/#mongodb-query-op.-nearSphere">
       <code class="leafygreen-ui-1l06pbn">
        $nearSphere
       </code>
      </a>
      operators on time series collections
     </p>
    </div>
   </div>
   <span class="leafygreen-ui-1qnjd6d" id="std-label-geospatial-aggregation">
   </span>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Geospatial Aggregation Stage
    <a class="headerlink leafygreen-ui-1kepx47" href="#geospatial-aggregation-stage" title="Permalink to this heading">
     <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
      <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
      </path>
      <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
      </path>
     </svg>
     <div class="css-1btu0w3 evvkmar0" id="geospatial-aggregation-stage">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    MongoDB provides the following geospatial
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline">
     aggregation pipeline
stage
     <!-- -->
     :
    </a>
   </p>
   <div class="leafygreen-ui-skkc39" tabindex="0">
    <table class="leafygreen-ui-hr8lsv">
     <colgroup>
      <col style="width:38%"/>
      <col style="width:72%"/>
     </colgroup>
     <thead class="leafygreen-ui-a9ho40">
      <tr data-testid="leafygreen-ui-header-row">
       <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
        <div class="leafygreen-ui-ui0te9">
         <div>
          Stage
         </div>
        </div>
       </th>
       <th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
        <div class="leafygreen-ui-ui0te9">
         <div>
          Description
         </div>
        </div>
       </th>
      </tr>
     </thead>
     <tbody>
      <tr class="">
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/geoNear/#mongodb-pipeline-pipe.-geoNear">
           <code class="leafygreen-ui-1l06pbn">
            $geoNear
           </code>
          </a>
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          <p class="leafygreen-ui-1kp3ins">
           Returns an ordered stream of documents based on the proximity to a
geospatial point. Incorporates the functionality of
           <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/match/#mongodb-pipeline-pipe.-match">
            <code class="leafygreen-ui-1l06pbn">
             $match
            </code>
           </a>
           ,
           <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sort/#mongodb-pipeline-pipe.-sort">
            <code class="leafygreen-ui-1l06pbn">
             $sort
            </code>
           </a>
           , and
           <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/limit/#mongodb-pipeline-pipe.-limit">
            <code class="leafygreen-ui-1l06pbn">
             $limit
            </code>
           </a>
           for
geospatial data. The output documents include an additional distance
field and can include a location identifier field.
          </p>
          <p class="leafygreen-ui-1kp3ins">
           <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/geoNear/#mongodb-pipeline-pipe.-geoNear">
            <code class="leafygreen-ui-1l06pbn">
             $geoNear
            </code>
           </a>
           requires a
           <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-index-feature-geospatial" target="_self">
            <span>
             geospatial index
             <!-- -->
             .
            </span>
           </a>
          </p>
         </div>
        </div>
       </td>
      </tr>
     </tbody>
    </table>
   </div>
   <p class="leafygreen-ui-1kp3ins">
    For more details, including examples, see
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/geoNear/#mongodb-pipeline-pipe.-geoNear">
     <code class="leafygreen-ui-1l06pbn">
      $geoNear
     </code>
    </a>
    reference page.
   </p>
   <span class="leafygreen-ui-1qnjd6d" id="std-label-geospatial-geometry">
   </span>
  </section>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Geospatial Models
   <a class="headerlink leafygreen-ui-1kepx47" href="#geospatial-models" title="Permalink to this heading">
    <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
     <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
     </path>
     <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
     </path>
    </svg>
    <div class="css-1btu0w3 evvkmar0" id="geospatial-models">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   MongoDB geospatial queries can interpret geometry on a flat surface or
a sphere.
  </p>
  <p class="leafygreen-ui-1kp3ins">
   <code class="leafygreen-ui-1l06pbn">
    2dsphere
   </code>
   indexes support only spherical queries (i.e. queries that
interpret geometries on a spherical surface).
  </p>
  <p class="leafygreen-ui-1kp3ins">
   <code class="leafygreen-ui-1l06pbn">
    2d
   </code>
   indexes support flat queries (i.e. queries that interpret
geometries on a flat surface) and some spherical queries. While
   <code class="leafygreen-ui-1l06pbn">
    2d
   </code>
   indexes support some spherical queries, the use of
   <code class="leafygreen-ui-1l06pbn">
    2d
   </code>
   indexes for
these spherical queries can result in error. If possible, use
   <code class="leafygreen-ui-1l06pbn">
    2dsphere
   </code>
   indexes for spherical queries.
  </p>
  <p class="leafygreen-ui-1kp3ins">
   The following table lists the geospatial query operators, supported
query, used by each geospatial operations:
  </p>
  <div class="leafygreen-ui-skkc39" tabindex="0">
   <table class="leafygreen-ui-hr8lsv">
    <colgroup>
     <col style="width:48%"/>
     <col style="width:12%"/>
     <col style="width:40%"/>
    </colgroup>
    <thead class="leafygreen-ui-a9ho40">
     <tr data-testid="leafygreen-ui-header-row">
      <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
       <div class="leafygreen-ui-ui0te9">
        <div>
         Operation
        </div>
       </div>
      </th>
      <th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
       <div class="leafygreen-ui-ui0te9">
        <div>
         Spherical/Flat Query
        </div>
       </div>
      </th>
      <th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
       <div class="leafygreen-ui-ui0te9">
        <div>
         Notes
        </div>
       </div>
      </th>
     </tr>
    </thead>
    <tbody>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/near/#mongodb-query-op.-near">
          <code class="leafygreen-ui-1l06pbn">
           $near
          </code>
         </a>
         (
         <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geospatial-geojson" target="_self">
          <span>
           GeoJSON
          </span>
         </a>
         centroid
point in this line and the following line,
         <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geo-2dsphere" target="_self">
          <span>
           2dsphere
          </span>
         </a>
         index)
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         Spherical
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         See also the
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/nearSphere/#mongodb-query-op.-nearSphere">
          <code class="leafygreen-ui-1l06pbn">
           $nearSphere
          </code>
         </a>
         operator, which provides the
same functionality when used with
         <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geospatial-geojson" target="_self">
          <span>
           GeoJSON
          </span>
         </a>
         and a
         <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geo-2dsphere" target="_self">
          <span>
           2dsphere
          </span>
         </a>
         index.
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/near/#mongodb-query-op.-near">
          <code class="leafygreen-ui-1l06pbn">
           $near
          </code>
         </a>
         (
         <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geospatial-legacy" target="_self">
          <span>
           legacy coordinates
          </span>
         </a>
         ,
         <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geo-2d" target="_self">
          <span>
           2d
          </span>
         </a>
         index)
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         Flat
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/nearSphere/#mongodb-query-op.-nearSphere">
          <code class="leafygreen-ui-1l06pbn">
           $nearSphere
          </code>
         </a>
         (
         <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geospatial-geojson" target="_self">
          <span>
           GeoJSON
          </span>
         </a>
         point,
         <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geo-2dsphere" target="_self">
          <span>
           2dsphere
          </span>
         </a>
         index)
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         Spherical
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <p class="leafygreen-ui-1kp3ins">
          Provides the same functionality as
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/near/#mongodb-query-op.-near">
           <code class="leafygreen-ui-1l06pbn">
            $near
           </code>
          </a>
          operation that
uses
          <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geospatial-geojson" target="_self">
           <span>
            GeoJSON
           </span>
          </a>
          point and a
          <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geo-2dsphere" target="_self">
           <span>
            2dsphere
           </span>
          </a>
          index.
         </p>
         <p class="leafygreen-ui-1kp3ins">
          For spherical queries, it may be preferable to use
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/nearSphere/#mongodb-query-op.-nearSphere">
           <code class="leafygreen-ui-1l06pbn">
            $nearSphere
           </code>
          </a>
          which explicitly specifies the spherical
queries in the name rather than
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/near/#mongodb-query-op.-near">
           <code class="leafygreen-ui-1l06pbn">
            $near
           </code>
          </a>
          operator.
         </p>
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/nearSphere/#mongodb-query-op.-nearSphere">
          <code class="leafygreen-ui-1l06pbn">
           $nearSphere
          </code>
         </a>
         (
         <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geospatial-legacy" target="_self">
          <span>
           legacy coordinates
          </span>
         </a>
         ,
         <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geo-2d" target="_self">
          <span>
           2d
          </span>
         </a>
         index)
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         Spherical
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         Use
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-GeoJSON">
          GeoJSON
         </a>
         points instead.
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/geoWithin/#mongodb-query-op.-geoWithin">
          <code class="leafygreen-ui-1l06pbn">
           $geoWithin
          </code>
         </a>
         : {
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/geometry/#mongodb-query-op.-geometry">
          <code class="leafygreen-ui-1l06pbn">
           $geometry
          </code>
         </a>
         : ... }
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         Spherical
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/geoWithin/#mongodb-query-op.-geoWithin">
          <code class="leafygreen-ui-1l06pbn">
           $geoWithin
          </code>
         </a>
         : {
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/box/#mongodb-query-op.-box">
          <code class="leafygreen-ui-1l06pbn">
           $box
          </code>
         </a>
         : ... }
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         Flat
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/geoWithin/#mongodb-query-op.-geoWithin">
          <code class="leafygreen-ui-1l06pbn">
           $geoWithin
          </code>
         </a>
         : {
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/polygon/#mongodb-query-op.-polygon">
          <code class="leafygreen-ui-1l06pbn">
           $polygon
          </code>
         </a>
         : ... }
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         Flat
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/geoWithin/#mongodb-query-op.-geoWithin">
          <code class="leafygreen-ui-1l06pbn">
           $geoWithin
          </code>
         </a>
         : {
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/center/#mongodb-query-op.-center">
          <code class="leafygreen-ui-1l06pbn">
           $center
          </code>
         </a>
         : ... }
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         Flat
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/geoWithin/#mongodb-query-op.-geoWithin">
          <code class="leafygreen-ui-1l06pbn">
           $geoWithin
          </code>
         </a>
         : {
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/centerSphere/#mongodb-query-op.-centerSphere">
          <code class="leafygreen-ui-1l06pbn">
           $centerSphere
          </code>
         </a>
         : ... }
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         Spherical
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/geoIntersects/#mongodb-query-op.-geoIntersects">
          <code class="leafygreen-ui-1l06pbn">
           $geoIntersects
          </code>
         </a>
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         Spherical
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/geoNear/#mongodb-pipeline-pipe.-geoNear">
          <code class="leafygreen-ui-1l06pbn">
           $geoNear
          </code>
         </a>
         aggregation stage (
         <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geo-2dsphere" target="_self">
          <span>
           2dsphere
          </span>
         </a>
         index)
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         Spherical
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/geoNear/#mongodb-pipeline-pipe.-geoNear">
          <code class="leafygreen-ui-1l06pbn">
           $geoNear
          </code>
         </a>
         aggregation stage (
         <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geo-2d" target="_self">
          <span>
           2d
          </span>
         </a>
         index)
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         Flat
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
        </div>
       </div>
      </td>
     </tr>
    </tbody>
   </table>
  </div>
  <span class="leafygreen-ui-1qnjd6d" id="std-label-geospatial-queries-atlas">
  </span>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Perform Geospatial Queries in Atlas
   <a class="headerlink leafygreen-ui-1kepx47" href="#perform-geospatial-queries-in-atlas" title="Permalink to this heading">
    <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
     <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
     </path>
     <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
     </path>
    </svg>
    <div class="css-1btu0w3 evvkmar0" id="perform-geospatial-queries-in-atlas">
    </div>
   </a>
  </h2>
  <div aria-hidden="true">
  </div>
  <div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs">
   <div class="leafygreen-ui-jp7pox" id="tabs-20">
    <div aria-label="Tabs to describe usage of aggregation/filter-bar" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
     <button aria-controls="_totm7wzlz" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_a7w4zcb3w" name="" role="tab" tabindex="0">
      <div class="leafygreen-ui-1nxuzmg">
       Query Filter Bar
      </div>
     </button>
     <button aria-controls="_5hzykgtbc" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_s9pe0uthu" name="" role="tab" tabindex="-1">
      <div class="leafygreen-ui-1nxuzmg">
       Aggregation
      </div>
     </button>
    </div>
    <div class="leafygreen-ui-ov1ktg">
     <div class="leafygreen-ui-1sg2lsz">
     </div>
    </div>
   </div>
   <div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
    <div>
     <div aria-labelledby="_xnfp52xy0" class="" id="_hknq692g0" role="tabpanel">
      <div class="leafygreen-ui-1kdmo88">
       <p class="leafygreen-ui-1kp3ins">
        You can use the MongoDB Atlas UI
to perform geospatial queries in Atlas.
       </p>
       <script class="structured_data" type="application/ld+json">
        {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"If your geospatial collection does not already have a geospatial\nindex, you must create one.Select the database for the collection.The main panel and Namespaces on the left side\nlist the collections in the database.Select the collection.Select the collection that contains your geospatial data on\nthe left-hand side or in the main panel. The main panel displays\nthe Find, Indexes, and\nAggregation views.Select the Index view.When you open the Index view, Atlas\ndisplays any indexes that exist on the collection.Define the Index for the geo TypePress the Create Index button.Define a geo Type index. Refer to\nHow to Index GeoJSON Objects.","name":"Create an index"},{"@type":"HowToStep","text":"Select the Find view.From the collection that contains your geospatial\ndata, select the Find tab to view your geospatial\ncollection.Enter a query.Enter a query in the Filter text box. Use\nany of the geospatial query operators to perform the relevant query\non your geospatial data. A geospatial query might resemble:Press the Apply button.Press the Apply button to apply your query.\nAtlas filters the geospatial data to show only documents\nthat match your geospatial query.","name":"Query the geospatial data"}],"name":"Perform Geospatial Queries in Atlas - Query Filter Bar","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
       </script>
       <div class="css-4nyere eccljxs0">
        <div class="css-1nuklj8 e1ckbxcu1">
         <div class="css-18fui5z e1ckbxcu0">
          <div class="css-19lsqsq e1ckbxcu2">
           1
          </div>
         </div>
         <div class="css-1ed38mk">
          <section>
           <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
            Create an index
            <a class="headerlink leafygreen-ui-1kepx47" href="#create-an-index" title="Permalink to this heading">
             <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
              <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
              </path>
              <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
              </path>
             </svg>
             <div class="css-1btu0w3 evvkmar0" id="create-an-index">
             </div>
            </a>
           </h3>
           <p class="leafygreen-ui-1kp3ins">
            If your geospatial collection does not already have a geospatial
index, you must create one.
           </p>
           <ol class="leafygreen-ui-rioki0" type="1">
            <li class="leafygreen-ui-d7p7b6">
             <p class="leafygreen-ui-1kp3ins">
              Select the database for the collection.
             </p>
             <p class="leafygreen-ui-1kp3ins">
              The main panel and
              <span class="guilabel css-h15tq0">
               Namespaces
              </span>
              on the left side
list the collections in the database.
             </p>
            </li>
            <li class="leafygreen-ui-d7p7b6">
             <p class="leafygreen-ui-1kp3ins">
              Select the collection.
             </p>
             <p class="leafygreen-ui-1kp3ins">
              Select the collection that contains your geospatial data on
the left-hand side or in the main panel. The main panel displays
the
              <span class="guilabel css-h15tq0">
               Find
              </span>
              ,
              <span class="guilabel css-h15tq0">
               Indexes
              </span>
              , and
              <span class="guilabel css-h15tq0">
               Aggregation
              </span>
              views.
             </p>
            </li>
            <li class="leafygreen-ui-d7p7b6">
             <p class="leafygreen-ui-1kp3ins">
              Select the Index view.
             </p>
             <p class="leafygreen-ui-1kp3ins">
              When you open the
              <span class="guilabel css-h15tq0">
               Index
              </span>
              view, Atlas
displays any indexes that exist on the collection.
             </p>
            </li>
            <li class="leafygreen-ui-d7p7b6">
             <p class="leafygreen-ui-1kp3ins">
              Define the Index for the geo Type
             </p>
             <p class="leafygreen-ui-1kp3ins">
              Press the
              <span class="guilabel css-h15tq0">
               Create Index
              </span>
              button.
             </p>
             <p class="leafygreen-ui-1kp3ins">
              Define a geo Type index. Refer to
              <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/field-types/geo-type/" target="_self">
               <span>
                How to Index GeoJSON Objects
                <!-- -->
                .
               </span>
              </a>
             </p>
            </li>
           </ol>
          </section>
         </div>
        </div>
        <div class="css-1nuklj8 e1ckbxcu1">
         <div class="css-18fui5z e1ckbxcu0">
          <div class="css-19lsqsq e1ckbxcu2">
           2
          </div>
         </div>
         <div class="css-1ed38mk">
          <section>
           <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
            Query the geospatial data
            <a class="headerlink leafygreen-ui-1kepx47" href="#query-the-geospatial-data" title="Permalink to this heading">
             <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
              <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
              </path>
              <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
              </path>
             </svg>
             <div class="css-1btu0w3 evvkmar0" id="query-the-geospatial-data">
             </div>
            </a>
           </h3>
           <ol class="leafygreen-ui-rioki0" type="1">
            <li class="leafygreen-ui-d7p7b6">
             <p class="leafygreen-ui-1kp3ins">
              Select the Find view.
             </p>
             <p class="leafygreen-ui-1kp3ins">
              From the collection that contains your geospatial
data, select the
              <span class="guilabel css-h15tq0">
               Find
              </span>
              tab to view your geospatial
collection.
             </p>
            </li>
            <li class="leafygreen-ui-d7p7b6">
             <p class="leafygreen-ui-1kp3ins">
              Enter a query.
             </p>
             <p class="leafygreen-ui-1kp3ins">
              Enter a query in the
              <span class="guilabel css-h15tq0">
               Filter
              </span>
              text box. Use
any of the
              <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-geospatial-operators" target="_self">
               <span>
                geospatial query operators
               </span>
              </a>
              to perform the relevant query
on your geospatial data. A geospatial query might resemble:
             </p>
             <script class="structured_data" type="application/ld+json">
              {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n  \"coordinates\": {\n    $geoWithin: {\n      $geometry: {\n        type: \"Polygon\",\n        coordinates: [\n          [\n            [-80.0, 10.00], [ -80.0, 9.00], [ -79.0, 9.0], [ -79.0, 10.00 ], [ -80.0, 10.0 ]\n          ]\n        ]\n      }\n    }\n  }\n}","programmingLanguage":"JavaScript"}
             </script>
             <div class="css-16lmvu9">
              <div class="leafygreen-ui-196mwvg">
               <div class="leafygreen-ui-yzcs8i">
                <pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <span class="lg-highlight-string">"coordinates"</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-attr">$geoWithin</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">$geometry</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">        <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"Polygon"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">        <span class="lg-highlight-attr">coordinates</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx">          <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx">            <!-- -->[<!-- -->-<span class="lg-highlight-number">80.0</span>, <span class="lg-highlight-number">10.00</span>]<!-- -->, <!-- -->[ <!-- -->-<span class="lg-highlight-number">80.0</span>, <span class="lg-highlight-number">9.00</span>]<!-- -->, <!-- -->[ <!-- -->-<span class="lg-highlight-number">79.0</span>, <span class="lg-highlight-number">9.0</span>]<!-- -->, <!-- -->[ <!-- -->-<span class="lg-highlight-number">79.0</span>, <span class="lg-highlight-number">10.00</span> ]<!-- -->, <!-- -->[ <!-- -->-<span class="lg-highlight-number">80.0</span>, <span class="lg-highlight-number">10.0</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">          ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">        ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
                <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
                 <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
                  <div class="leafygreen-ui-xhlipt">
                   <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
                    <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
                    </path>
                   </svg>
                  </div>
                 </button>
                </div>
               </div>
              </div>
             </div>
            </li>
            <li class="leafygreen-ui-d7p7b6">
             <p class="leafygreen-ui-1kp3ins">
              Press the Apply button.
             </p>
             <p class="leafygreen-ui-1kp3ins">
              Press the
              <span class="guilabel css-h15tq0">
               Apply
              </span>
              button to apply your query.
Atlas filters the geospatial data to show only documents
that match your geospatial query.
             </p>
            </li>
           </ol>
          </section>
         </div>
        </div>
       </div>
      </div>
     </div>
    </div>
    <div>
     <div aria-labelledby="_abol26cnz" class="leafygreen-ui-38lglc" id="_rjsmml9e9" role="tabpanel">
      <div class="leafygreen-ui-1kdmo88">
       <p class="leafygreen-ui-1kp3ins">
        You can create and execute aggregation pipelines to perform geospatial
queries in the MongoDB Atlas UI.
       </p>
       <script class="structured_data" type="application/ld+json">
        {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Select the database for the collection.The main panel and Namespaces on the left side list the\ncollections in the database.Select the collection.Select the collection that contains your geospatial data on\nthe left-hand side or in the main panel. The main panel displays\nthe Find, Indexes, and\nAggregation views.Select the Aggregation view.When you first open the Aggregation view, Atlas\ndisplays an empty aggregation pipeline.","name":"Access the aggregation pipeline builder"},{"@type":"HowToStep","text":"Select an aggregation stage.Select an aggregation stage from the Select dropdown in\nthe bottom-left panel.The toggle to the right of the dropdown dictates whether the\nstage is enabled.Use the $geoNear stage to perform geospatial\nqueries in your aggregation pipeline.Fill in your aggregation stage.Fill in your stage with the appropriate values.\nIf Comment Mode is enabled, the pipeline\nbuilder provides syntactic guidelines for your selected stage.As you modify your stage, Atlas updates the preview documents on\nthe right based on the results of the current stage.Your $geoNear stage may resemble:Run other pipeline stages as needed.Add stages as needed to complete your aggregation pipeline.\nYou might add $out or\n$merge to write the results to a\nview or the current collection.","name":"Create your geospatial query aggregation pipeline"}],"name":"Perform Geospatial Queries in Atlas - Aggregation","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
       </script>
       <div class="css-4nyere eccljxs0">
        <div class="css-1nuklj8 e1ckbxcu1">
         <div class="css-18fui5z e1ckbxcu0">
          <div class="css-19lsqsq e1ckbxcu2">
           1
          </div>
         </div>
         <div class="css-1ed38mk">
          <section>
           <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
            Access the aggregation pipeline builder
            <a class="headerlink leafygreen-ui-1kepx47" href="#access-the-aggregation-pipeline-builder" title="Permalink to this heading">
             <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
              <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
              </path>
              <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
              </path>
             </svg>
             <div class="css-1btu0w3 evvkmar0" id="access-the-aggregation-pipeline-builder">
             </div>
            </a>
           </h3>
           <ol class="leafygreen-ui-rioki0" type="1">
            <li class="leafygreen-ui-d7p7b6">
             <p class="leafygreen-ui-1kp3ins">
              Select the database for the collection.
             </p>
             <p class="leafygreen-ui-1kp3ins">
              The main panel and
              <span class="guilabel css-h15tq0">
               Namespaces
              </span>
              on the left side list the
collections in the database.
             </p>
            </li>
            <li class="leafygreen-ui-d7p7b6">
             <p class="leafygreen-ui-1kp3ins">
              Select the collection.
             </p>
             <p class="leafygreen-ui-1kp3ins">
              Select the collection that contains your geospatial data on
the left-hand side or in the main panel. The main panel displays
the
              <span class="guilabel css-h15tq0">
               Find
              </span>
              ,
              <span class="guilabel css-h15tq0">
               Indexes
              </span>
              , and
              <span class="guilabel css-h15tq0">
               Aggregation
              </span>
              views.
             </p>
            </li>
            <li class="leafygreen-ui-d7p7b6">
             <p class="leafygreen-ui-1kp3ins">
              Select the Aggregation view.
             </p>
             <p class="leafygreen-ui-1kp3ins">
              When you first open the
              <span class="guilabel css-h15tq0">
               Aggregation
              </span>
              view, Atlas
displays an empty aggregation pipeline.
             </p>
            </li>
           </ol>
          </section>
         </div>
        </div>
        <div class="css-1nuklj8 e1ckbxcu1">
         <div class="css-18fui5z e1ckbxcu0">
          <div class="css-19lsqsq e1ckbxcu2">
           2
          </div>
         </div>
         <div class="css-1ed38mk">
          <section>
           <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
            Create your geospatial query aggregation pipeline
            <a class="headerlink leafygreen-ui-1kepx47" href="#create-your-geospatial-query-aggregation-pipeline" title="Permalink to this heading">
             <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
              <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
              </path>
              <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
              </path>
             </svg>
             <div class="css-1btu0w3 evvkmar0" id="create-your-geospatial-query-aggregation-pipeline">
             </div>
            </a>
           </h3>
           <ol class="leafygreen-ui-rioki0" type="1">
            <li class="leafygreen-ui-d7p7b6">
             <p class="leafygreen-ui-1kp3ins">
              Select an aggregation stage.
             </p>
             <p class="leafygreen-ui-1kp3ins">
              Select an aggregation stage from the
              <span class="guilabel css-h15tq0">
               Select
              </span>
              dropdown in
the bottom-left panel.
             </p>
             <p class="leafygreen-ui-1kp3ins">
              The toggle to the right of the dropdown dictates whether the
stage is enabled.
             </p>
             <p class="leafygreen-ui-1kp3ins">
              Use the
              <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/geoNear/#mongodb-pipeline-pipe.-geoNear">
               <code class="leafygreen-ui-1l06pbn">
                $geoNear
               </code>
              </a>
              stage to perform geospatial
queries in your aggregation pipeline.
             </p>
            </li>
            <li class="leafygreen-ui-d7p7b6">
             <p class="leafygreen-ui-1kp3ins">
              Fill in your aggregation stage.
             </p>
             <p class="leafygreen-ui-1kp3ins">
              Fill in your stage with the appropriate values.
If
              <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-ui/agg-pipeline/#std-label-pipeline-settings" target="_self">
               <span>
                Comment Mode
               </span>
              </a>
              is enabled, the pipeline
builder provides syntactic guidelines for your selected stage.
             </p>
             <p class="leafygreen-ui-1kp3ins">
              As you modify your stage, Atlas updates the preview documents on
the right based on the results of the current stage.
             </p>
             <p class="leafygreen-ui-1kp3ins">
              Your
              <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/geoNear/#mongodb-pipeline-pipe.-geoNear">
               <code class="leafygreen-ui-1l06pbn">
                $geoNear
               </code>
              </a>
              stage may resemble:
             </p>
             <script class="structured_data" type="application/ld+json">
              {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n  near: { type: \"Point\", coordinates: [ -73.9667, 40.78 ] },\n  spherical: true,\n  query: { category: \"Parks\" },\n  distanceField: \"calcDistance\"\n}","programmingLanguage":"JavaScript"}
             </script>
             <div class="css-16lmvu9">
              <div class="leafygreen-ui-196mwvg">
               <div class="leafygreen-ui-yzcs8i">
                <pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <span class="lg-highlight-attr">near</span>: <!-- -->{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"Point"</span>, <span class="lg-highlight-attr">coordinates</span>: <!-- -->[ <!-- -->-<span class="lg-highlight-number">73.9667</span>, <span class="lg-highlight-number">40.78</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <span class="lg-highlight-attr">spherical</span>: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">"Parks"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <span class="lg-highlight-attr">distanceField</span>: <span class="lg-highlight-string">"calcDistance"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
                <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
                 <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
                  <div class="leafygreen-ui-xhlipt">
                   <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
                    <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
                    </path>
                   </svg>
                  </div>
                 </button>
                </div>
               </div>
              </div>
             </div>
            </li>
            <li class="leafygreen-ui-d7p7b6">
             <p class="leafygreen-ui-1kp3ins">
              Run other pipeline stages as needed.
             </p>
             <p class="leafygreen-ui-1kp3ins">
              Add stages as needed to complete your aggregation pipeline.
You might add
              <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/out/#mongodb-pipeline-pipe.-out">
               <code class="leafygreen-ui-1l06pbn">
                $out
               </code>
              </a>
              or
              <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge">
               <code class="leafygreen-ui-1l06pbn">
                $merge
               </code>
              </a>
              to write the results to a
view or the current collection.
             </p>
            </li>
           </ol>
          </section>
         </div>
        </div>
       </div>
      </div>
     </div>
    </div>
   </div>
  </div>
  <span class="leafygreen-ui-1qnjd6d" id="std-label-geospatial-query-examples">
  </span>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Examples
   <a class="headerlink leafygreen-ui-1kepx47" href="#examples" title="Permalink to this heading">
    <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
     <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
     </path>
     <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
     </path>
    </svg>
    <div class="css-1btu0w3 evvkmar0" id="examples">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   Create a collection
   <code class="leafygreen-ui-1l06pbn">
    places
   </code>
   with the following documents:
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.places.insertMany( [\n   {\n      name: \"Central Park\",\n      location: { type: \"Point\", coordinates: [ -73.97, 40.77 ] },\n      category: \"Parks\"\n   },\n   {\n      name: \"Sara D. Roosevelt Park\",\n      location: { type: \"Point\", coordinates: [ -73.9928, 40.7193 ] },\n      category: \"Parks\"\n   },\n   {\n      name: \"Polo Grounds\",\n      location: { type: \"Point\", coordinates: [ -73.9375, 40.8303 ] },\n      category: \"Stadiums\"\n   }\n] )","programmingLanguage":"JavaScript"}
  </script>
  <div class="css-16lmvu9">
   <div class="leafygreen-ui-196mwvg">
    <div class="leafygreen-ui-1b1bvay">
     <pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">places</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Central Park"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">location</span>: <!-- -->{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"Point"</span>, <span class="lg-highlight-attr">coordinates</span>: <!-- -->[ <!-- -->-<span class="lg-highlight-number">73.97</span>, <span class="lg-highlight-number">40.77</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">"Parks"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">   }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Sara D. Roosevelt Park"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">location</span>: <!-- -->{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"Point"</span>, <span class="lg-highlight-attr">coordinates</span>: <!-- -->[ <!-- -->-<span class="lg-highlight-number">73.9928</span>, <span class="lg-highlight-number">40.7193</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">"Parks"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">   }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Polo Grounds"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">location</span>: <!-- -->{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"Point"</span>, <span class="lg-highlight-attr">coordinates</span>: <!-- -->[ <!-- -->-<span class="lg-highlight-number">73.9375</span>, <span class="lg-highlight-number">40.8303</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">"Stadiums"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">   }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
     <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
      <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
       <div class="leafygreen-ui-xhlipt">
        <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
         <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
         </path>
        </svg>
       </div>
      </button>
     </div>
    </div>
   </div>
  </div>
  <p class="leafygreen-ui-1kp3ins">
   The following operation creates a
   <code class="leafygreen-ui-1l06pbn">
    2dsphere
   </code>
   index on the
   <code class="leafygreen-ui-1l06pbn">
    location
   </code>
   field:
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.places.createIndex( { location: \"2dsphere\" } )","programmingLanguage":"JavaScript"}
  </script>
  <div class="css-16lmvu9">
   <div class="leafygreen-ui-196mwvg">
    <div class="leafygreen-ui-yzcs8i">
     <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">places</span>.<span class="lg-highlight-title lg-highlight-function">createIndex</span>( <!-- -->{ <span class="lg-highlight-attr">location</span>: <span class="lg-highlight-string">"2dsphere"</span> } )</td></tr></tbody></table></code></pre>
     <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
      <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
       <div class="leafygreen-ui-xhlipt">
        <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
         <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
         </path>
        </svg>
       </div>
      </button>
     </div>
    </div>
   </div>
  </div>
  <p class="leafygreen-ui-1kp3ins">
   The
   <code class="leafygreen-ui-1l06pbn">
    places
   </code>
   collection above has a
   <code class="leafygreen-ui-1l06pbn">
    2dsphere
   </code>
   index.
The following query uses the
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/near/#mongodb-query-op.-near">
    <code class="leafygreen-ui-1l06pbn">
     $near
    </code>
   </a>
   operator to return
documents that are at least 1000 meters from and at most 5000 meters
from the specified GeoJSON point, sorted in order from nearest to
farthest:
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.places.find(\n   {\n     location:\n       { $near:\n          {\n            $geometry: { type: \"Point\",  coordinates: [ -73.9667, 40.78 ] },\n            $minDistance: 1000,\n            $maxDistance: 5000\n          }\n       }\n   }\n)","programmingLanguage":"JavaScript"}
  </script>
  <div class="css-16lmvu9">
   <div class="leafygreen-ui-196mwvg">
    <div class="leafygreen-ui-1b1bvay">
     <pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">places</span>.<span class="lg-highlight-title lg-highlight-function">find</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">     <span class="lg-highlight-attr">location</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">       <!-- -->{ <span class="lg-highlight-attr">$near</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">          <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">            <span class="lg-highlight-attr">$geometry</span>: <!-- -->{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"Point"</span>,  <span class="lg-highlight-attr">coordinates</span>: <!-- -->[ <!-- -->-<span class="lg-highlight-number">73.9667</span>, <span class="lg-highlight-number">40.78</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">            <span class="lg-highlight-attr">$minDistance</span>: <span class="lg-highlight-number">1000</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">            <span class="lg-highlight-attr">$maxDistance</span>: <span class="lg-highlight-number">5000</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">          }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">       }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
     <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
      <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
       <div class="leafygreen-ui-xhlipt">
        <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
         <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
         </path>
        </svg>
       </div>
      </button>
     </div>
    </div>
   </div>
  </div>
  <p class="leafygreen-ui-1kp3ins">
   The following operation uses the
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/geoNear/#mongodb-pipeline-pipe.-geoNear">
    <code class="leafygreen-ui-1l06pbn">
     $geoNear
    </code>
   </a>
   aggregation
operation to return documents that match the query filter
   <code class="leafygreen-ui-1l06pbn">
    { category:
"Parks" }
   </code>
   , sorted in order of nearest to farthest to the specified
GeoJSON point:
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.places.aggregate( [\n   {\n      $geoNear: {\n         near: { type: \"Point\", coordinates: [ -73.9667, 40.78 ] },\n         spherical: true,\n         query: { category: \"Parks\" },\n         distanceField: \"calcDistance\"\n      }\n   }\n] )","programmingLanguage":"JavaScript"}
  </script>
  <div class="css-16lmvu9">
   <div class="leafygreen-ui-196mwvg">
    <div class="leafygreen-ui-1b1bvay">
     <pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">places</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">$geoNear</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">near</span>: <!-- -->{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"Point"</span>, <span class="lg-highlight-attr">coordinates</span>: <!-- -->[ <!-- -->-<span class="lg-highlight-number">73.9667</span>, <span class="lg-highlight-number">40.78</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">spherical</span>: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">"Parks"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">distanceField</span>: <span class="lg-highlight-string">"calcDistance"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">      }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">] )</td></tr></tbody></table></code></pre>
     <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
      <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
       <div class="leafygreen-ui-xhlipt">
        <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
         <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
         </path>
        </svg>
       </div>
      </button>
     </div>
    </div>
   </div>
  </div>
 </section>
</section>
