@@ -120,57 +120,43 @@ in the previous example:
120
120
121
121
Limit
122
122
`````
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
-
128
123
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:
136
128
137
129
.. code-block:: javascript
138
130
139
131
db.collection.find( { <location field>: { $near: [ x, y ] } } ).limit(n)
140
132
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:
143
136
144
137
.. code-block:: javascript
145
138
146
139
db.runCommand( { geoNear: "collection", near: [ x, y ], num: z } )
147
140
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.
159
145
160
146
.. note::
161
147
162
148
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`.
168
152
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.
170
158
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...
174
160
175
161
.. index:: geospatial queries; distance limit
176
162
@@ -179,15 +165,19 @@ please see the :ref:`geospatial-query-distance` section.
179
165
Distance
180
166
````````
181
167
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.
186
171
187
172
.. code-block:: javascript
188
173
189
174
db.collection.find( { <location field>: { $near: [ x, y ] } , $maxDistance : z } )
190
175
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
+
191
181
:dbcommand:`geoNear` provides equivalent functionality with the
192
182
``maxDistance`` option, as in the following prototype:
193
183
0 commit comments