From 31901590015e9be04a7f607e25b15ac342ad6149 Mon Sep 17 00:00:00 2001 From: ian fogelman Date: Tue, 9 Nov 2021 11:13:26 -0500 Subject: [PATCH 1/4] 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 c23f6a9c052..c628a23090e 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 e2e0edbe9a0..2127733c90e 100644 --- a/source/reference/operator/aggregation/geoNear.txt +++ b/source/reference/operator/aggregation/geoNear.txt @@ -204,17 +204,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 e7c364e3a86db73161bbd3b2e7aba4f7e18d0222 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/4] Update source/includes/geospatial-places-data-setup.rst Co-authored-by: jeff-allen-mongo --- .../includes/geospatial-places-data-setup.rst | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 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: From 54a65586ff619862c3700a5d74bd261abf85f2cd 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/4] Update source/includes/geospatial-places-data-setup.rst Co-authored-by: jeff-allen-mongo --- source/reference/operator/aggregation/geoNear.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/reference/operator/aggregation/geoNear.txt b/source/reference/operator/aggregation/geoNear.txt index 2127733c90e..71bb2a33dda 100644 --- a/source/reference/operator/aggregation/geoNear.txt +++ b/source/reference/operator/aggregation/geoNear.txt @@ -216,7 +216,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 da043ec9e65fdf881039a3045e3cddd83efd840d 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 4/4] 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 c628a23090e..21460327c91 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