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