From 015c14643dec463b5715ec3e77e59286594963fe Mon Sep 17 00:00:00 2001 From: ian fogelman Date: Tue, 9 Nov 2021 11:13:26 -0500 Subject: [PATCH 1/3] DOCS-14900 adding geospatial data setup to geoNear page --- source/geospatial-queries.txt | 32 +++---------------- .../includes/geospatial-places-data-setup.rst | 26 +++++++++++++++ .../operator/aggregation/geoNear.txt | 17 ++++++---- 3 files changed, 41 insertions(+), 34 deletions(-) create mode 100644 source/includes/geospatial-places-data-setup.rst diff --git a/source/geospatial-queries.txt b/source/geospatial-queries.txt index 9c7703c0dd7..dd482142728 100644 --- a/source/geospatial-queries.txt +++ b/source/geospatial-queries.txt @@ -291,36 +291,12 @@ query, used by each geospatial operations: - Flat - -Example -------- +Examples +-------- -Create a collection ``places`` with the following documents: - -.. code-block:: javascript - - db.places.insert( { - name: "Central Park", - location: { type: "Point", coordinates: [ -73.97, 40.77 ] }, - category: "Parks" - } ); - db.places.insert( { - name: "Sara D. Roosevelt Park", - location: { type: "Point", coordinates: [ -73.9928, 40.7193 ] }, - category: "Parks" - } ); - db.places.insert( { - name: "Polo Grounds", - location: { type: "Point", coordinates: [ -73.9375, 40.8303 ] }, - category: "Stadiums" - } ); - -The following operation creates a ``2dsphere`` index on the -``location`` field: - -.. code-block:: javascript - - db.places.createIndex( { location: "2dsphere" } ) +.. include:: /includes/geospatial-places-data-setup.rst +Consider the ``places`` collection above, it has a ``2dsphere`` index. The following query uses the :query:`$near` 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 diff --git a/source/includes/geospatial-places-data-setup.rst b/source/includes/geospatial-places-data-setup.rst new file mode 100644 index 00000000000..06ddece59aa --- /dev/null +++ b/source/includes/geospatial-places-data-setup.rst @@ -0,0 +1,26 @@ +Create a collection ``places`` with the following documents: + +.. code-block:: javascript + + db.places.insert( { + name: "Central Park", + location: { type: "Point", coordinates: [ -73.97, 40.77 ] }, + category: "Parks" + } ); + db.places.insert( { + name: "Sara D. Roosevelt Park", + location: { type: "Point", coordinates: [ -73.9928, 40.7193 ] }, + category: "Parks" + } ); + db.places.insert( { + name: "Polo Grounds", + location: { type: "Point", coordinates: [ -73.9375, 40.8303 ] }, + category: "Stadiums" + } ); + +The following operation creates a ``2dsphere`` index on the +``location`` field: + +.. code-block:: javascript + + db.places.createIndex( { location: "2dsphere" } ) \ No newline at end of file diff --git a/source/reference/operator/aggregation/geoNear.txt b/source/reference/operator/aggregation/geoNear.txt index b964c806c2e..7cd1c50911a 100644 --- a/source/reference/operator/aggregation/geoNear.txt +++ b/source/reference/operator/aggregation/geoNear.txt @@ -203,17 +203,22 @@ When using :pipeline:`$geoNear`, consider that: - Starting in version 4.2, :pipeline:`$geoNear` no longer has a default limit of 100 documents. -Example -------- +Examples +-------- + +.. include:: /includes/geospatial-places-data-setup.rst + +Maximum Distance +~~~~~~~~~~~~~~~~ .. note:: .. include:: /includes/extracts/4.2-changes-geoNear-limit.rst -Consider a collection ``places`` that has a ``2dsphere`` index. The -following aggregation uses :pipeline:`$geoNear` to find documents with -a location at most 2 meters from the center ``[ -73.99279 , 40.719296 -]`` and ``category`` equal to ``Parks``. +Consider the ``places`` collection above, it has a ``2dsphere`` index. +The following aggregation uses :pipeline:`$geoNear` to find documents +with a location at most 2 meters from the center +``[ -73.99279 , 40.719296 ]`` and ``category`` equal to ``Parks``. .. code-block:: javascript From a93553008b06d3f4d47f1bc6b5dca7210d0168ba Mon Sep 17 00:00:00 2001 From: ianf-mongodb <85948430+ianf-mongodb@users.noreply.github.com> Date: Wed, 10 Nov 2021 10:20:36 -0500 Subject: [PATCH 2/3] Update source/includes/geospatial-places-data-setup.rst Co-authored-by: jeff-allen-mongo --- .../includes/geospatial-places-data-setup.rst | 32 ++++++++++--------- .../operator/aggregation/geoNear.txt | 2 +- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/source/includes/geospatial-places-data-setup.rst b/source/includes/geospatial-places-data-setup.rst index 06ddece59aa..90833abc7fb 100644 --- a/source/includes/geospatial-places-data-setup.rst +++ b/source/includes/geospatial-places-data-setup.rst @@ -2,21 +2,23 @@ Create a collection ``places`` with the following documents: .. code-block:: javascript - db.places.insert( { - name: "Central Park", - location: { type: "Point", coordinates: [ -73.97, 40.77 ] }, - category: "Parks" - } ); - db.places.insert( { - name: "Sara D. Roosevelt Park", - location: { type: "Point", coordinates: [ -73.9928, 40.7193 ] }, - category: "Parks" - } ); - db.places.insert( { - name: "Polo Grounds", - location: { type: "Point", coordinates: [ -73.9375, 40.8303 ] }, - category: "Stadiums" - } ); + db.places.insertMany( [ + { + name: "Central Park", + location: { type: "Point", coordinates: [ -73.97, 40.77 ] }, + category: "Parks" + }, + { + name: "Sara D. Roosevelt Park", + location: { type: "Point", coordinates: [ -73.9928, 40.7193 ] }, + category: "Parks" + }, + { + name: "Polo Grounds", + location: { type: "Point", coordinates: [ -73.9375, 40.8303 ] }, + category: "Stadiums" + } + ] ) The following operation creates a ``2dsphere`` index on the ``location`` field: diff --git a/source/reference/operator/aggregation/geoNear.txt b/source/reference/operator/aggregation/geoNear.txt index 7cd1c50911a..15b8880a2ca 100644 --- a/source/reference/operator/aggregation/geoNear.txt +++ b/source/reference/operator/aggregation/geoNear.txt @@ -215,7 +215,7 @@ Maximum Distance .. include:: /includes/extracts/4.2-changes-geoNear-limit.rst -Consider the ``places`` collection above, it has a ``2dsphere`` index. +The ``places`` collection above has a ``2dsphere`` index. The following aggregation uses :pipeline:`$geoNear` to find documents with a location at most 2 meters from the center ``[ -73.99279 , 40.719296 ]`` and ``category`` equal to ``Parks``. From 59ef0f0355ea5703c9e3ba45de8f014935890be4 Mon Sep 17 00:00:00 2001 From: ianf-mongodb <85948430+ianf-mongodb@users.noreply.github.com> Date: Wed, 10 Nov 2021 10:20:36 -0500 Subject: [PATCH 3/3] Update source/includes/geospatial-places-data-setup.rst Co-authored-by: jeff-allen-mongo --- source/geospatial-queries.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/geospatial-queries.txt b/source/geospatial-queries.txt index dd482142728..99be29173f8 100644 --- a/source/geospatial-queries.txt +++ b/source/geospatial-queries.txt @@ -296,7 +296,7 @@ Examples .. include:: /includes/geospatial-places-data-setup.rst -Consider the ``places`` collection above, it has a ``2dsphere`` index. +The ``places`` collection above has a ``2dsphere`` index. The following query uses the :query:`$near` 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