Skip to content

Commit 5c55376

Browse files
DOCS-14900 adding geospatial data setup to geoNear page (#6105)
* DOCS-14900 adding geospatial data setup to geoNear page * Update source/reference/operator/aggregation/geoNear.txt 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 1874da8 commit 5c55376

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,19 @@ When using :pipeline:`$geoNear`, consider that:
211211
Examples
212212
--------
213213

214+
.. include:: /includes/geospatial-places-data-setup.rst
215+
214216
Maximum Distance
215217
~~~~~~~~~~~~~~~~
216218

217219
.. note::
218220

219221
.. include:: /includes/extracts/4.2-changes-geoNear-limit.rst
220222

221-
Consider a collection ``places`` that has a ``2dsphere`` index. The
222-
following aggregation uses :pipeline:`$geoNear` to find documents with
223-
a location at most 2 meters from the center ``[ -73.99279 , 40.719296
224-
]`` and ``category`` equal to ``Parks``.
223+
The ``places`` collection above has a ``2dsphere`` index.
224+
The following aggregation uses :pipeline:`$geoNear` to find documents
225+
with a location at most 2 meters from the center
226+
``[ -73.99279 , 40.719296 ]`` and ``category`` equal to ``Parks``.
225227

226228
.. code-block:: javascript
227229

0 commit comments

Comments
 (0)