Skip to content

Commit 02305ec

Browse files
author
Andrew Leung
committed
editing save
1 parent 141178d commit 02305ec

File tree

1 file changed

+28
-38
lines changed

1 file changed

+28
-38
lines changed

draft/applications/geospatial-indexes.txt

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -120,57 +120,43 @@ in the previous example:
120120

121121
Limit
122122
`````
123-
124-
.. TODO double check with greg... will limit really stop 100 documents
125-
.. being searched for (i.e. if only 99 documents are found, limit(98)
126-
.. will return sooner? )
127-
128123
The :func:`limit() <cursor.limit()>` method can be used with
129-
:func:`find() <db.collection.find()>` to limit the
130-
131-
By default, geospatial queries with :func:`find()
132-
<db.collection.find()>` return 100 documents sorted by distance. To limit
133-
on the result set, use the :func:`limit() <cursor.limit()>` method
134-
with :func:`find() <db.collection.find()>` operator. The following is
135-
the prototype operation:
124+
:func:`find() <db.collection.find()>` to limit the number of results.
125+
By default, geospatial queries with the :func:`find()
126+
<db.collection.find()>` method return 100 documents sorted by
127+
distance. The following is the prototype operation:
136128

137129
.. code-block:: javascript
138130

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

141-
To the ``num`` option with the :dbcommand:`geoNear`
142-
command and the ``near`` parameter, as in the following prototype:
133+
To limit the result set using the :dbcommand:`geoNear` command, use
134+
the ``num`` option to limit results. The following is a prototype of
135+
the command:
143136

144137
.. code-block:: javascript
145138

146139
db.runCommand( { geoNear: "collection", near: [ x, y ], num: z } )
147140

148-
The following command returns the same results as the :operator:`near`
149-
in the previous example:
150-
151-
.. code-block:: javascript
152-
153-
db.runCommand( { geoNear: "collection", near: [ -74, 40.74 ], num: 20 } )
154-
155-
The :func:`limit() <cursor.limit()>` method and ``near`` parameter do not limit
156-
geospatial query results by distance, only the number of returned
157-
:term:`document`. To limit geospatial search results by distance,
158-
please see the :ref:`geospatial-query-distance` section.
141+
The :func:`limit() <cursor.limit()>` method and ``near`` parameter do
142+
not limit geospatial query results by distance, only the number of
143+
results. To limit geospatial search results by distance, please see
144+
the :ref:`geospatial-query-distance` section.
159145

160146
.. note::
161147

162148
The :func:`limit() <cursor.limit()>` method and ``num`` option have
163-
different performance characteristics. Geospatial queries with
164-
:func:`limit() <cursor.limit()>` method will return 100 documents,
165-
sort them, and finally the limit method is applied. Geospatial
166-
queries with ``num`` option will only return the specified number
167-
of documents unsorted.
149+
different performance characteristics. Geospatial queries using
150+
:func:`limit() <cursor.limit()>` method are slower than using
151+
:dbcommand:`geoNear`.
168152

169-
.. note::
153+
Geospatial queries with the :func:`find() <db.collection.find()>`
154+
method will return 100 documents, sort them, and finally limit the
155+
result set. Geospatial queries with the :dbcommand:`geoNear` and
156+
``num`` option will only return the specified number of unsorted
157+
documents.
170158

171-
Limits in geospatial queries are always applied to the geospatial
172-
component first. This will affect the results if you specify
173-
additional sort operations.
159+
.. TODO double check with greg...
174160

175161
.. index:: geospatial queries; distance limit
176162

@@ -179,15 +165,19 @@ please see the :ref:`geospatial-query-distance` section.
179165
Distance
180166
````````
181167

182-
To limit the result set by a distance from the query point, MongoDB
183-
provides the :operator:`$maxDistance` operator that you can use in
184-
:func:`find() <db.collection.find()>` queries with the
185-
:operator:`$near` operator, as in the following prototype:
168+
To query geospatial data by distance, use the :operator:`$maxDistance` operator
169+
with :func:`find() <db.collection.find()>`. Results with this operator
170+
will not exceed the distance specified.
186171

187172
.. code-block:: javascript
188173

189174
db.collection.find( { <location field>: { $near: [ x, y ] } , $maxDistance : z } )
190175

176+
To limit the result set by a distance from the query point, MongoDB
177+
provides the :operator:`$maxDistance` operator that you can use in
178+
:func:`find() <db.collection.find()>` queries with the
179+
:operator:`$near` operator, as in the following prototype:
180+
191181
:dbcommand:`geoNear` provides equivalent functionality with the
192182
``maxDistance`` option, as in the following prototype:
193183

0 commit comments

Comments
 (0)