@@ -13,7 +13,15 @@ Geospatial Queries
1313 :class: singlecol
1414
1515MongoDB supports query operations on geospatial data. This section
16- introduces MongoDB's geospatial features.
16+ introduces MongoDB's geospatial features.
17+
18+ .. |page-topic| replace:: run geospatial queries
19+
20+ .. include:: /includes/fact-atlas-compatible.rst
21+
22+ For deployments hosted in {+atlas+}, you can run geospatial
23+ queries in the UI by using the query :guilabel:`Filter` bar or aggregation
24+ builder. To learn more, see :ref:`geospatial-queries-atlas`.
1725
1826.. _geo-overview-location-data:
1927
@@ -270,6 +278,156 @@ query, used by each geospatial operations:
270278 - Flat
271279 -
272280
281+ .. _geospatial-queries-atlas:
282+
283+ Perform Geospatial Queries in Atlas
284+ -----------------------------------
285+
286+ .. tabs::
287+
288+ .. tab:: Query Filter Bar
289+ :tabid: filter-bar
290+
291+ You can use the {+atlas+} UI
292+ to perform geospatial queries in Atlas.
293+
294+ .. procedure::
295+ :style: normal
296+
297+ .. step:: Create an index
298+
299+ If your geospatial collection does not already have a geospatial
300+ index, you must create one.
301+
302+ 1. Select the database for the collection.
303+
304+ The main panel and :guilabel:`Namespaces` on the left side
305+ list the collections in the database.
306+
307+ #. Select the collection.
308+
309+ Select the collection that contains your geospatial data on
310+ the left-hand side or in the main panel. The main panel displays
311+ the :guilabel:`Find`, :guilabel:`Indexes`, and
312+ :guilabel:`Aggregation` views.
313+
314+ #. Select the Index view.
315+
316+ When you open the :guilabel:`Index` view, Atlas
317+ displays any indexes that exist on the collection.
318+
319+ #. Define the Index for the geo Type
320+
321+ Press the :guilabel:`Create Index` button.
322+
323+ Define a geo Type index. Refer to
324+ `How to Index GeoJSON Objects <https://www.mongodb.com/docs/atlas/atlas-search/field-types/geo-type/>`__.
325+
326+ .. step:: Query the geospatial data
327+
328+ 1. Select the Find view.
329+
330+ From the collection that contains your geospatial
331+ data, select the :guilabel:`Find` tab to view your geospatial
332+ collection.
333+
334+ #. Enter a query.
335+
336+ Enter a query in the :guilabel:`Filter` text box. Use
337+ any of the :ref:`geospatial query operators
338+ <geospatial-operators>` to perform the relevant query
339+ on your geospatial data. A geospatial query might resemble:
340+
341+ .. code-block:: javascript
342+
343+ {
344+ "coordinates": {
345+ $geoWithin: {
346+ $geometry: {
347+ type: "Polygon",
348+ coordinates: [
349+ [
350+ [-80.0, 10.00], [ -80.0, 9.00], [ -79.0, 9.0], [ -79.0, 10.00 ], [ -80.0, 10.0 ]
351+ ]
352+ ]
353+ }
354+ }
355+ }
356+ }
357+
358+ #. Press the Apply button.
359+
360+ Press the :guilabel:`Apply` button to apply your query.
361+ Atlas filters the geospatial data to show only documents
362+ that match your geospatial query.
363+
364+ .. tab:: Aggregation
365+ :tabid: aggregation
366+
367+ You can create and execute aggregation pipelines to perform geospatial
368+ queries in the {+atlas+} UI.
369+
370+ .. procedure::
371+ :style: normal
372+
373+ .. step:: Access the aggregation pipeline builder
374+
375+ 1. Select the database for the collection.
376+
377+ The main panel and :guilabel:`Namespaces` on the left side list the
378+ collections in the database.
379+
380+ #. Select the collection.
381+
382+ Select the collection that contains your geospatial data on
383+ the left-hand side or in the main panel. The main panel displays
384+ the :guilabel:`Find`, :guilabel:`Indexes`, and
385+ :guilabel:`Aggregation` views.
386+
387+ #. Select the Aggregation view.
388+
389+ When you first open the :guilabel:`Aggregation` view, Atlas
390+ displays an empty aggregation pipeline.
391+
392+ .. step:: Create your geospatial query aggregation pipeline
393+
394+ 1. Select an aggregation stage.
395+
396+ Select an aggregation stage from the :guilabel:`Select` dropdown in
397+ the bottom-left panel.
398+
399+ The toggle to the right of the dropdown dictates whether the
400+ stage is enabled.
401+
402+ Use the :pipeline:`$geoNear` stage to perform geospatial
403+ queries in your aggregation pipeline.
404+
405+ #. Fill in your aggregation stage.
406+
407+ Fill in your stage with the appropriate values.
408+ If :ref:`Comment Mode <pipeline-settings>` is enabled, the pipeline
409+ builder provides syntactic guidelines for your selected stage.
410+
411+ As you modify your stage, Atlas updates the preview documents on
412+ the right based on the results of the current stage.
413+
414+ Your :pipeline:`$geoNear` stage may resemble:
415+
416+ .. code-block:: javascript
417+
418+ {
419+ near: { type: "Point", coordinates: [ -73.9667, 40.78 ] },
420+ spherical: true,
421+ query: { category: "Parks" },
422+ distanceField: "calcDistance"
423+ }
424+
425+ #. Run other pipeline stages as needed.
426+
427+ Add stages as needed to complete your aggregation pipeline.
428+ You might add :pipeline:`$out` or
429+ :pipeline:`$merge` to write the results to a
430+ view or the current collection.
273431
274432.. _geospatial-query-examples:
275433
0 commit comments