Skip to content

Commit d9ea258

Browse files
DOCS-14900 adding geospatial data setup to geoNear page (#6107)
* DOCS-14900 adding geospatial data setup to geoNear page * Update source/includes/geospatial-places-data-setup.rst Co-authored-by: jeff-allen-mongo <jeffrey.allen@10gen.com> * Update source/includes/geospatial-places-data-setup.rst Co-authored-by: jeff-allen-mongo <jeffrey.allen@10gen.com> * Update source/includes/geospatial-places-data-setup.rst Co-authored-by: jeff-allen-mongo <jeffrey.allen@10gen.com> Co-authored-by: jeff-allen-mongo <jeffrey.allen@10gen.com>
1 parent d0e1d43 commit d9ea258

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
@@ -204,17 +204,22 @@ When using :pipeline:`$geoNear`, consider that:
204204
- Starting in version 4.2, :pipeline:`$geoNear` no longer has a default
205205
limit of 100 documents.
206206

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

210215
.. note::
211216

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

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

219224
.. code-block:: javascript
220225

0 commit comments

Comments
 (0)