Skip to content

Commit fb658b7

Browse files
DOCS-14900 adding geospatial data setup to geoNear page (#6108)
* DOCS-14900 adding geospatial data setup to geoNear page * Update source/includes/geospatial-places-data-setup.rst Co-authored-by: jeff-allen-mongo <[email protected]> * Update source/includes/geospatial-places-data-setup.rst Co-authored-by: jeff-allen-mongo <[email protected]> Co-authored-by: jeff-allen-mongo <[email protected]>
1 parent c8aa96f commit fb658b7

File tree

3 files changed

+43
-34
lines changed

3 files changed

+43
-34
lines changed

source/geospatial-queries.txt

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -291,36 +291,12 @@ query, used by each geospatial operations:
291291
- Flat
292292
-
293293

294-
Example
295-
-------
294+
Examples
295+
--------
296296

297-
Create a collection ``places`` with the following documents:
298-
299-
.. code-block:: javascript
300-
301-
db.places.insert( {
302-
name: "Central Park",
303-
location: { type: "Point", coordinates: [ -73.97, 40.77 ] },
304-
category: "Parks"
305-
} );
306-
db.places.insert( {
307-
name: "Sara D. Roosevelt Park",
308-
location: { type: "Point", coordinates: [ -73.9928, 40.7193 ] },
309-
category: "Parks"
310-
} );
311-
db.places.insert( {
312-
name: "Polo Grounds",
313-
location: { type: "Point", coordinates: [ -73.9375, 40.8303 ] },
314-
category: "Stadiums"
315-
} );
316-
317-
The following operation creates a ``2dsphere`` index on the
318-
``location`` field:
319-
320-
.. code-block:: javascript
321-
322-
db.places.createIndex( { location: "2dsphere" } )
297+
.. include:: /includes/geospatial-places-data-setup.rst
323298

299+
The ``places`` collection above has a ``2dsphere`` index.
324300
The following query uses the :query:`$near` operator to return
325301
documents that are at least 1000 meters from and at most 5000 meters
326302
from the specified GeoJSON point, sorted in order from nearest to
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Create a collection ``places`` with the following documents:
2+
3+
.. code-block:: javascript
4+
5+
db.places.insertMany( [
6+
{
7+
name: "Central Park",
8+
location: { type: "Point", coordinates: [ -73.97, 40.77 ] },
9+
category: "Parks"
10+
},
11+
{
12+
name: "Sara D. Roosevelt Park",
13+
location: { type: "Point", coordinates: [ -73.9928, 40.7193 ] },
14+
category: "Parks"
15+
},
16+
{
17+
name: "Polo Grounds",
18+
location: { type: "Point", coordinates: [ -73.9375, 40.8303 ] },
19+
category: "Stadiums"
20+
}
21+
] )
22+
23+
The following operation creates a ``2dsphere`` index on the
24+
``location`` field:
25+
26+
.. code-block:: javascript
27+
28+
db.places.createIndex( { location: "2dsphere" } )

source/reference/operator/aggregation/geoNear.txt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,17 +203,22 @@ When using :pipeline:`$geoNear`, consider that:
203203
- Starting in version 4.2, :pipeline:`$geoNear` no longer has a default
204204
limit of 100 documents.
205205

206-
Example
207-
-------
206+
Examples
207+
--------
208+
209+
.. include:: /includes/geospatial-places-data-setup.rst
210+
211+
Maximum Distance
212+
~~~~~~~~~~~~~~~~
208213

209214
.. note::
210215

211216
.. include:: /includes/extracts/4.2-changes-geoNear-limit.rst
212217

213-
Consider a collection ``places`` that has a ``2dsphere`` index. The
214-
following aggregation uses :pipeline:`$geoNear` to find documents with
215-
a location at most 2 meters from the center ``[ -73.99279 , 40.719296
216-
]`` and ``category`` equal to ``Parks``.
218+
The ``places`` collection above has a ``2dsphere`` index.
219+
The following aggregation uses :pipeline:`$geoNear` to find documents
220+
with a location at most 2 meters from the center
221+
``[ -73.99279 , 40.719296 ]`` and ``category`` equal to ``Parks``.
217222

218223
.. code-block:: javascript
219224

0 commit comments

Comments
 (0)