Skip to content

Commit dd4342b

Browse files
author
Sam Kleinman
committed
merge: DODC-934
2 parents ac284c0 + 82861e1 commit dd4342b

File tree

5 files changed

+71
-27
lines changed

5 files changed

+71
-27
lines changed

source/core/geospatial-indexes.txt

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,21 @@
77
Overview
88
--------
99

10-
``2d`` geospatial indexes support efficient queries using
11-
location-based data in a document, and special geospatial query
12-
operators. You can store two-dimensional location coordinates in
13-
documents and with a geospatial index on this field, construct
14-
location-based queries. For example, you can query for documents based
15-
on proximity to another location or based on inclusion in a specified
10+
``2d`` geospatial indexes make it possible to associate documents with
11+
locations in two-dimensional space, such as a point on a map. MongoDB
12+
interprets two-dimensional coordinates in a location field, as points
13+
and can index these points in a special index type to support
14+
location-based queries. Geospatial indexes provide special geospatial
15+
query operators. For example, you can query for documents based on
16+
proximity to another location or based on inclusion in a specified
1617
region.
1718

18-
Additionally, geospatial indexes support queries on both the
19-
coordinate field *and* another field. For example, you might write a
20-
query to find restaurants a specific distance from a hotel or to find
21-
museums found within a certain defined neighborhood.
19+
Geospatial indexes support queries on both the coordinate field *and*
20+
another field, such as a type of business or attraction. For example,
21+
you might write a query to find restaurants a specific distance from a
22+
hotel or to find museums within a certain defined neighborhood.
2223

23-
This document describes how to include location data in your documents
24+
This document describes how to store location data in your documents
2425
and how to create geospatial indexes. For information on querying data
2526
stored in geospatial indexes, see :doc:`/applications/geospatial-indexes`.
2627

@@ -31,17 +32,17 @@ Store Location Data
3132

3233
To use ``2d`` geospatial indexes, you must model location data on a
3334
predetermined two-dimensional coordinate system, such as longitude
34-
and latitude. You store location data as two-dimensional coordinates
35+
and latitude. You store a document's location data as two coordinates
3536
in a field that holds either a two-dimensional array or an embedded
36-
document. Consider the following two examples:
37+
document with two fields. Consider the following two examples:
3738

3839
.. code-block:: javascript
3940

4041
loc : [ x, y ]
4142

4243
loc : { x: 1, y: 2 }
4344

44-
All documents must store location data in the same order; however, if
45+
All documents must store location data in the same order. If
4546
you use latitude and longitude as your coordinate system, always store
4647
longitude first. MongoDB's :ref:`2d spherical index operators
4748
<geospatial-indexes-spherical>` only recognize ``[ longitude, latitude
@@ -63,7 +64,7 @@ location field of your collection. Consider the following prototype:
6364

6465
db.collection.ensureIndex( { <location field> : "2d" } )
6566

66-
MongoDB's special :ref:`geospatial operations
67+
MongoDB's :ref:`geospatial operations
6768
<geospatial-query-operators>` use this index when querying for location
6869
data.
6970

@@ -87,12 +88,12 @@ Location Range
8788
~~~~~~~~~~~~~~
8889

8990
All ``2d`` geospatial indexes have boundaries defined by a coordinate
90-
range. By default, ``2s`` geospatial indexes assume longitude and
91+
range. By default, ``2d`` geospatial indexes assume longitude and
9192
latitude have boundaries of -180 inclusive and 180 non-inclusive
9293
(i.e. ``[-180, 180)``). MongoDB returns an error and rejects documents
9394
with coordinate data outside of the specified range.
9495

95-
To build an index with a different location range other than the
96+
To build an index with a location range other than the
9697
default, use the ``min`` and ``max`` options with the
9798
:method:`ensureIndex() <db.collection.ensureIndex()>` operation when
9899
creating a ``2d`` index, as in the following prototype:
@@ -253,8 +254,8 @@ for geospatial information based on a sphere or earth.
253254
.. admonition:: Spherical Queries Use Radians for Distance
254255

255256
For spherical operators to function properly, you must convert
256-
distances to radians, and convert from radians to distances units
257-
for your application.
257+
distances to radians, and convert from radians to the distances units
258+
used by your application.
258259

259260
To convert:
260261

source/includes/note-geospatial-index-must-exist.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@
55
operators *without* having a geospatial index; however, geospatial
66
indexes will support much faster geospatial queries than the
77
unindexed equivalents.
8+
9+
.. note::
10+
11+
A geospatial index *must* exist on a field and the field must hold coordinates
12+
before you can use any of the geolocation query operators.

source/reference/operator/centerSphere.txt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,24 @@ $centerSphere
1010

1111
The :operator:`$centerSphere` operator is the spherical equivalent
1212
of the :operator:`$center` operator. :operator:`$centerSphere` uses
13-
spherical geometry to calculate distances in a circle specified by
14-
a point and radius.
13+
spherical geometry to define a circle for use by the
14+
:operator:`$within` operator in :term:`geospatial` queries.
1515

16-
Considering the following example:
16+
To define the bounds of a query using :operator:`$centerSphere`, you
17+
must specify:
1718

18-
.. code-block:: javascript
19+
- The center point
20+
21+
- The angular distance in radians (distance along the surface of the
22+
earth).
1923

20-
db.collection.find( { loc: { $within: { $centerSphere: [ [0,0], 10 / 3959 ] } } } )
24+
The following example returns all documents within a 10 mile radius
25+
of longitude ``88 W`` and latitude ``30 N``. The distance (10 miles)
26+
is converted to radians by dividing by the approximate radius of the
27+
earth (3959 miles).
28+
29+
.. code-block:: javascript
2130

22-
This query will return all documents within a 10 mile radius of
23-
``[0,0]`` using a spherical geometry to calculate distances.
31+
db.collection.find( { loc: { $within: { $centerSphere: { [88,30], 10 /* miles */ / 3959 /* miles */ } } } } )
2432

2533
.. include:: /includes/note-geospatial-index-must-exist.rst

source/reference/operator/within.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ $within
1515
db.collection.find( { location: { $within: { shape } } } );
1616

1717
Replace ``{ shape }`` with a document that describes a shape. The
18-
:operator:`$within` command supports three shapes. These shapes and the
18+
:operator:`$within` command supports the following shapes. These shapes and the
1919
relevant expressions follow:
2020

2121
- Rectangles. Use the :operator:`$box` operator, consider the following
@@ -35,6 +35,9 @@ $within
3535

3636
db.collection.find( { location: { $within: { $center: [ center, radius } } } );
3737

38+
- Circular distance on a sphere. Use the
39+
:operator:`$centerSphere` operator. For the syntax, see :operator:`$centerSphere`.
40+
3841
- Polygons. Use the :operator:`$polygon` operator. Specify polygons with an array of points. See the
3942
following example:
4043

source/reference/operators.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ Geospatial
105105
- :operator:`$near`
106106
- :operator:`$within`
107107

108+
.. include:: operator/near.txt
109+
:start-after: mongodb
110+
111+
.. include:: operator/nearSphere.txt
112+
:start-after: mongodb
113+
114+
.. include:: operator/within.txt
115+
:start-after: mongodb
116+
108117
Use the following operators within the context of
109118
:operator:`$within`:
110119

@@ -115,6 +124,24 @@ Use the following operators within the context of
115124
- :operator:`$polygon`
116125
- :operator:`$uniqueDocs`
117126

127+
.. include:: operator/maxDistance.txt
128+
:start-after: mongodb
129+
130+
.. include:: operator/center.txt
131+
:start-after: mongodb
132+
133+
.. include:: operator/centerSphere.txt
134+
:start-after: mongodb
135+
136+
.. include:: operator/box.txt
137+
:start-after: mongodb
138+
139+
.. include:: operator/polygon.txt
140+
:start-after: mongodb
141+
142+
.. include:: operator/uniqueDocs.txt
143+
:start-after: mongodb
144+
118145
.. index:: query selectors; array
119146
.. _query-selectors-array:
120147

0 commit comments

Comments
 (0)