Skip to content

DOCS-14900 adding geospatial data setup to geoNear page #6108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 4 additions & 28 deletions source/geospatial-queries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

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
Expand Down
28 changes: 28 additions & 0 deletions source/includes/geospatial-places-data-setup.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Create a collection ``places`` with the following documents:

.. code-block:: javascript

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:

.. code-block:: javascript

db.places.createIndex( { location: "2dsphere" } )
17 changes: 11 additions & 6 deletions source/reference/operator/aggregation/geoNear.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
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``.

.. code-block:: javascript

Expand Down