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