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
10
+ Geospatial indexing allows you to associate a document with a location
11
+ in two-dimensional space, such as a point on a map. You store
12
+ two-dimensional coordinates in a location field in your documents,
13
+ create a geospatial index on that field, and construct location-based
14
+ queries. Geospatial indexes provide special geospatial query operators.
15
+ For example, you can query for documents based
15
16
on 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
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
20
22
query to find restaurants a specific distance from a hotel or to find
21
- museums found within a certain defined neighborhood.
23
+ museums within a certain defined neighborhood.
22
24
23
- This document describes how to include location data in your documents
25
+ This document describes how to store location data in your documents
24
26
and how to create geospatial indexes. For information on querying data
25
27
stored in geospatial indexes, see :doc:`/applications/geospatial-indexes`.
26
28
@@ -31,17 +33,17 @@ Store Location Data
31
33
32
34
To use ``2d`` geospatial indexes, you must model location data on a
33
35
predetermined two-dimensional coordinate system, such as longitude
34
- and latitude. You store location data as two-dimensional coordinates
36
+ and latitude. You store a document's location data as two coordinates
35
37
in a field that holds either a two-dimensional array or an embedded
36
- document. Consider the following two examples:
38
+ document with two fields . Consider the following two examples:
37
39
38
40
.. code-block:: javascript
39
41
40
42
loc : [ x, y ]
41
43
42
44
loc : { x: 1, y: 2 }
43
45
44
- All documents must store location data in the same order; however, if
46
+ All documents must store location data in the same order. If
45
47
you use latitude and longitude as your coordinate system, always store
46
48
longitude first. MongoDB's :ref:`2d spherical index operators
47
49
<geospatial-indexes-spherical>` only recognize ``[ longitude, latitude
@@ -63,7 +65,7 @@ location field of your collection. Consider the following prototype:
63
65
64
66
db.collection.ensureIndex( { <location field> : "2d" } )
65
67
66
- MongoDB's special :ref:`geospatial operations
68
+ MongoDB's :ref:`geospatial operations
67
69
<geospatial-query-operators>` use this index when querying for location
68
70
data.
69
71
@@ -87,12 +89,12 @@ Location Range
87
89
~~~~~~~~~~~~~~
88
90
89
91
All ``2d`` geospatial indexes have boundaries defined by a coordinate
90
- range. By default, ``2s `` geospatial indexes assume longitude and
92
+ range. By default, ``2d `` geospatial indexes assume longitude and
91
93
latitude have boundaries of -180 inclusive and 180 non-inclusive
92
94
(i.e. ``[-180, 180)``). MongoDB returns an error and rejects documents
93
95
with coordinate data outside of the specified range.
94
96
95
- To build an index with a different location range other than the
97
+ To build an index with a location range other than the
96
98
default, use the ``min`` and ``max`` options with the
97
99
:method:`ensureIndex() <db.collection.ensureIndex()>` operation when
98
100
creating a ``2d`` index, as in the following prototype:
@@ -253,8 +255,8 @@ for geospatial information based on a sphere or earth.
253
255
.. admonition:: Spherical Queries Use Radians for Distance
254
256
255
257
For spherical operators to function properly, you must convert
256
- distances to radians, and convert from radians to distances units
257
- for your application.
258
+ distances to radians, and convert from radians to the distances units
259
+ used by your application.
258
260
259
261
To convert:
260
262
0 commit comments