Skip to content

geospatial indexes review edits #521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 11 additions & 28 deletions source/applications/geospatial-indexes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,17 @@ following form:

.. code-block:: javascript

db.places.find( { loc: {$near: [-70,40] } })
db.places.find( { loc: { $near: [ -70, 40 ] } } )

returns output similar to the following:

.. code-block:: javascript

{ "_id" : ObjectId(" ... "), "loc" : [ -73, 40 ] }
{ "_id" : ObjectId(" ... "), "loc" : [ -73, 39 ] }

The :dbcommand:`geoNear` command returns more information than does the
:operator:`$near` operator but does not sort results. The
:operator:`$near` operator. The :dbcommand:`geoNear` command is
limited to one, 16-megabyte set of results. The
:dbcommand:`geoNear` command also offers additional operators, such as
operators to query for :ref:`maximum <geospatial-indexes-distance>` or
:ref:`spherical <geospatial-indexes-spherical>` distance. For a list of
Expand Down Expand Up @@ -84,15 +85,14 @@ following form:

{
"ns" : "test.places",
"near" : "0110000111111000000111111000000111111000000111111000",
"results" : [
{
"dis" : 3,
"obj" : {
"_id" : ObjectId(" ... "),
"loc" : [
-73,
40
39
]
}
}
Expand All @@ -105,6 +105,7 @@ following form:
"avgDistance" : 3,
"maxDistance" : 3.0000188685220253
},
"near" : "0110000111111000000111111000000111111000000111111000",
"ok" : 1
}

Expand All @@ -124,7 +125,7 @@ method, use :operator:`$maxDistance` operator. Use the following form:

.. code-block:: javascript

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

To specify distance with the :dbcommand:`geoNear` command, use the
``maxDistance`` option. Use the following form:
Expand All @@ -140,9 +141,7 @@ Limit the Number of Results

By default, geospatial queries using :method:`find()
<db.collection.find()>` method return 100 documents, sorted by
distance.

To limit the result when using the :method:`find()
distance. To limit the result when using the :method:`find()
<db.collection.find()>` method, use the :method:`limit()
<cursor.limit()>` method, as in the following prototype:

Expand All @@ -151,30 +150,14 @@ To limit the result when using the :method:`find()
db.collection.find( { <location field>: { $near: [ x, y ] } } ).limit(<n>)

To limit the result set when using the :dbcommand:`geoNear` command, use
the ``num`` option. The following is a prototype of the command:
the ``num`` option. Use the following form:

.. code-block:: javascript

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

The :method:`limit() <cursor.limit()>` method and ``near`` parameter
to :dbcommand:`geoNear` do not limit geospatial query results by
distance, only the number of results. To limit geospatial search
results by distance, please see the :ref:`geospatial-indexes-distance`
section.

.. note::

The :method:`limit() <cursor.limit()>` method and ``num`` option have
different performance characteristics. Geospatial queries using
:method:`limit() <cursor.limit()>` method are slower than using
:dbcommand:`geoNear`.

Geospatial queries with the :method:`find() <db.collection.find()>`
method will return 100 documents, sort them, and finally limit the
result set. Geospatial queries with the :dbcommand:`geoNear` and
``num`` option will only return the specified number of unsorted
documents.
To limit geospatial search results by distance, see
:ref:`geospatial-indexes-distance`.

.. _geospatial-indexes-within:
.. _geospatial-indexes-bounded:
Expand Down