Skip to content

Commit 4cca966

Browse files
author
Andrew Leung
committed
re-editing geospatial apps
1 parent 4d68967 commit 4cca966

File tree

1 file changed

+51
-56
lines changed

1 file changed

+51
-56
lines changed

draft/applications/geospatial-indexes.txt

Lines changed: 51 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ Using Geospatial Data
44

55
.. default-domain:: mongodb
66

7-
MongoDB provides rich location aware queries that return documents
8-
based on location with a special geospatial index type. This document
9-
introduces geospatial data modeling, indexing operations, and provides
10-
example queries using the :ref:`geospatial query operators
11-
<geospatial-query-operators>`. For more information about
12-
geospatial indexes and operations see the :doc:`/core/geospatial-indexes` document.
7+
MongoDB provides functionality to store and query geospatial data with
8+
specialized operators. This document introduces geospatial data
9+
modeling, indexing operations, and provides example queries using the
10+
:ref:`geospatial query operators <geospatial-query-operators>`. For
11+
more information about geospatial indexes and operations see the
12+
:doc:`/core/geospatial-indexes` document.
1313

1414
.. _geospatial-coordinates:
1515

@@ -24,22 +24,27 @@ geospatial indexes and operations see the :doc:`/core/geospatial-indexes` docume
2424
Queries
2525
-------
2626

27-
MongoDB provides special :ref:`geospatial query operators
28-
<geospatial-query-operators>` for performing queries on location data
29-
inside the normal :func:`find() <db.collection.find()>` method. The
30-
:dbcommand:`geoNear` command also returns results using geospatial
31-
indexes, but also includes additional geospatial information in the
32-
return documents.
27+
There are two operators to query geospatial data in MongoDB,
28+
the general :func:`find() <db.collection.find()>` method and the
29+
specialized :dbcommand:`geoNear` command.
30+
31+
.. TODO find a better way to say this... (rewrite 3x)
32+
The :func:`find() <db.collection.find()>` method for geospatial data
33+
is same as querying any other data. This provides simplicity.
34+
35+
The :dbcommand:`geoNear` command is more specialized as it returns
36+
detailed geospatial information such as distances, ... This provides
37+
addtional benefit when only working with geospatial data.
38+
39+
.. TODO does it make sense to have this here??
3340

3441
.. note::
3542

36-
By default MongoDB assumes calculate distances using flat geometry
37-
and all distances calculated by the :dbcommand:`geoNear` use the
38-
Pythagorean distance formula.
43+
By default, MongoDB calculates distances using flat geometry.
3944

4045
MongoDB can also calculate distances based on :ref:`spherical
41-
geometry <geospatial-spherical-representation>`, using
42-
:ref:`spherical query operations <geospatial-spherical-queries>`.
46+
geometry <geospatial-spherical-representation>` by using the
47+
:ref:`spherical query operators <geospatial-spherical-queries>`.
4348

4449
.. index:: geospatial queries; exact
4550

@@ -49,25 +54,18 @@ Exact
4954
~~~~~
5055

5156
You can use the :func:`find() <db.collection.find()>` method to query
52-
for an exact match on a location. These queries take the
53-
following prototypical form:
57+
for an exact match on a location. These queries have the prototypical
58+
form:
5459

5560
.. code-block:: javascript
5661

5762
db.collection.find( { <location field>: [ x, y ] } )
5863

59-
This query will return any document that where the value of ``[ x, y
60-
]`` is *exactly* the same as the one specified in the query. To return
61-
all documents in the ``places`` collection with values in the ``loc``
62-
field that are exactly ``[ -74, 40.74 ]``, consider the following example:
64+
This query will return any documents with the value of ``[ x, y ]``.
6365

64-
.. code-block:: javascript
65-
66-
db.places.find( { "loc": [ -74, 40.74 ] } )
67-
68-
Exact geospatial queries only have applicability for a limited selection of
69-
cases, :ref:`proximity <geospatial-query-proximity>` and :ref:`bounded
70-
<geospatial-query-bounded>` provide more useful results.
66+
Exact geospatial queries have applicability for a limited selection of
67+
cases, the :ref:`proximity <geospatial-query-proximity>` method and :ref:`bounded
68+
<geospatial-query-bounded>` method provide more useful results.
7169

7270
.. index:: geospatial queries; proximity
7371
.. _geospatial-query-near:
@@ -76,32 +74,29 @@ cases, :ref:`proximity <geospatial-query-proximity>` and :ref:`bounded
7674
Proximity
7775
~~~~~~~~~
7876

79-
Proximity queries take a coordinate pair and return a result set of
80-
documents from the geospatial index that are close to the query
81-
coordinates, sorted by distance. You can use the :operator:`$near`
82-
operator in a :func:`find() <db.collection.find()>` query to return
83-
the 100 closest points to a coordinate (e.g. ``[ x, y ]``.) These
84-
queries have the following prototype form:
77+
To find all documents that are within a proximity of a point, use the
78+
:operator:`$near` operator with the :func:`find()
79+
<db.collection.find()>` method. By default, the :operator:`$near` will
80+
return 100 points sorted by distance.
81+
82+
The prototype form for the :operator:`$near` operator is:
8583

8684
.. code-block:: javascript
8785

8886
db.collection.find( { <location field>: { $near: [ x, y ] } } )
8987

90-
Consider the following example query:
91-
92-
.. code-block:: javascript
88+
.. TODO show example & output (i.e. show that it's the same as normal ops)
9389

94-
db.places.find( { loc: { $near: [ -74, 40.74 ] } } )
90+
The :dbcommand:`geoNear` command provides the equivalent functionality
91+
to the :operator:`$near` operator but does not sort the results,
92+
returns more information for each document found, and provides
93+
additional operators.
9594

96-
This operation will return documents from a collection named
97-
``places`` that has a geospatial index on the ``loc`` field, near the
98-
coordinates ``[ -74, 40.74 ]``.
95+
.. TODO what are the additional operators for geoNear that can't be
96+
.. used by find()??
9997

100-
In addition to :operator:`near`, the :dbcommand:`geoNear` command
101-
provides equivalent functionality. :dbcommand:`geoNear` adds
102-
additional options and returns more information for each
103-
document found. In its most simple form, the :dbcommand:`geoNear`
104-
command has the following prototypical form:
98+
In its most simple form, the :dbcommand:`geoNear` command has the
99+
following prototypical form:
105100

106101
.. code-block:: javascript
107102

@@ -114,6 +109,9 @@ in the previous example:
114109

115110
db.runCommand( {geoNear: "places", near: [ -74, 40.74 ] } )
116111

112+
.. TODO show output (i.e. highlight differences to $near)
113+
114+
117115
.. seealso::
118116

119117
:ref:`geospatial-query-exact`
@@ -123,8 +121,11 @@ in the previous example:
123121
Limit
124122
`````
125123

124+
The :func:`limit() <cursor.limit()>` method can be used with
125+
:func:`find() <db.collection.find()>`
126+
126127
By default, geospatial queries with :func:`find()
127-
<db.collection.find()>` return 100 documents. To impose a limit
128+
<db.collection.find()>` return 100 documents sorted by distance. To limit
128129
on the result set, use the :func:`limit() <cursor.limit()>` method
129130
with :func:`find() <db.collection.find()>` operator. The following is
130131
the prototype operation:
@@ -133,13 +134,7 @@ the prototype operation:
133134

134135
db.collection.find( { <location field>: { $near: [ x, y ] } } ).limit(n)
135136

136-
The following example will return only 20 results of the above query:
137-
138-
.. code-block:: javascript
139-
140-
db.places.find( { loc: { $near: [ -74, 40.74 ] } } ).limit(20)
141-
142-
You may also use the ``num`` option with the :dbcommand:`geoNear`
137+
To the ``num`` option with the :dbcommand:`geoNear`
143138
command and the ``near`` parameter, as in the following prototype:
144139

145140
.. code-block:: javascript

0 commit comments

Comments
 (0)