7
7
Overview
8
8
--------
9
9
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
16
17
region.
17
18
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.
22
23
23
- This document describes how to include location data in your documents
24
+ This document describes how to store location data in your documents
24
25
and how to create geospatial indexes. For information on querying data
25
26
stored in geospatial indexes, see :doc:`/applications/geospatial-indexes`.
26
27
@@ -31,17 +32,17 @@ Store Location Data
31
32
32
33
To use ``2d`` geospatial indexes, you must model location data on a
33
34
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
35
36
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:
37
38
38
39
.. code-block:: javascript
39
40
40
41
loc : [ x, y ]
41
42
42
43
loc : { x: 1, y: 2 }
43
44
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
45
46
you use latitude and longitude as your coordinate system, always store
46
47
longitude first. MongoDB's :ref:`2d spherical index operators
47
48
<geospatial-indexes-spherical>` only recognize ``[ longitude, latitude
@@ -63,7 +64,7 @@ location field of your collection. Consider the following prototype:
63
64
64
65
db.collection.ensureIndex( { <location field> : "2d" } )
65
66
66
- MongoDB's special :ref:`geospatial operations
67
+ MongoDB's :ref:`geospatial operations
67
68
<geospatial-query-operators>` use this index when querying for location
68
69
data.
69
70
@@ -87,12 +88,12 @@ Location Range
87
88
~~~~~~~~~~~~~~
88
89
89
90
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
91
92
latitude have boundaries of -180 inclusive and 180 non-inclusive
92
93
(i.e. ``[-180, 180)``). MongoDB returns an error and rejects documents
93
94
with coordinate data outside of the specified range.
94
95
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
96
97
default, use the ``min`` and ``max`` options with the
97
98
:method:`ensureIndex() <db.collection.ensureIndex()>` operation when
98
99
creating a ``2d`` index, as in the following prototype:
@@ -253,8 +254,8 @@ for geospatial information based on a sphere or earth.
253
254
.. admonition:: Spherical Queries Use Radians for Distance
254
255
255
256
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.
258
259
259
260
To convert:
260
261
0 commit comments