Skip to content

Commit 049d9a1

Browse files
committed
DOCS-11099: tweak wording for key for $geoNear in 4.2
1 parent e110f2f commit 049d9a1

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

source/includes/apiargs-pipeline-geoNear-field.yaml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,22 @@ arg_name: field
164164
interface: pipeline
165165
operation: geoNear
166166
description: |
167-
Specify the geospatial index to use when calculating the distance.
168-
If your collection has multiple geospatial indexes, you **must**
169-
use the ``key`` option to specify the indexed field path to use.
170-
:ref:`pipeline-geoNear-key-param-example` provides a full example.
167+
168+
Specify the geospatial indexed field to use when calculating the
169+
distance.
170+
171+
If your collection has multiple ``2d`` and/or multiple ``2dsphere``
172+
indexes, you **must** use the ``key`` option to specify the indexed
173+
field path to use. :ref:`pipeline-geoNear-key-param-example`
174+
provides a full example.
175+
176+
If there is more than one ``2d`` index or more than one ``2dsphere``
177+
index and you do not specify a ``key``, MongoDB will return an error.
171178
172-
If you do not specify the field over which to perform the search with
173-
``key``, MongoDB will attempt to look for a usable ``2d`` or
174-
``2dsphere`` index, in that order. If there is more than one ``2d``
175-
index or more than one ``2dsphere`` index, MongoDB will return an
176-
error.
179+
If you do not specify the ``key``, and you have at most only one
180+
``2d`` index and/or only one ``2dsphere`` index, MongoDB looks first
181+
for a ``2d`` index to use. If a ``2d`` index does not exists, then
182+
MongoDB looks for a ``2dsphere`` index to use.
177183
178184
.. versionadded:: 4.0
179185
Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
The :pipeline:`$geoNear` pipeline stage requires that a collection has
2-
*at most* only one |first-geo-index| and/or only one |second-geo-index|
3-
whereas :ref:`geospatial query operators <geospatial-query-selectors>`
4-
(e.g. :query:`$near` and :query:`$geoWithin`) permit collections to
5-
have multiple geospatial indexes.
6-
7-
The geospatial index restriction for the command and the pipeline stage
8-
exists because neither the command nor the pipeline stage syntax
9-
includes the location field. As such, index selection among multiple
10-
``2d`` indexes or ``2dsphere`` indexes is ambiguous.
11-
12-
No such restriction applies for :ref:`geospatial query operators
13-
<geospatial-query-selectors>` since these operators take a location
14-
field, eliminating the ambiguity.
1+
Starting in MongoDB 4.0, you can specify a ``key`` option to the
2+
:pipeline:`$geoNear` pipeline stage to indicate the indexed field path
3+
to use. This allows the :pipeline:`$geoNear` stage to be used on a
4+
collection that has multiple |first-geo-index| and/or multiple
5+
|second-geo-index|:
6+
7+
- If your collection has multiple |first-geo-index| and/or multiple
8+
|second-geo-index|, you must use the ``key`` option to specify the
9+
indexed field path to use.
10+
11+
- If you do not specify the ``key``, you cannot have multiple
12+
|first-geo-index| and/or multiple |second-geo-index| since without
13+
the ``key``, index selection among multiple ``2d`` indexes or
14+
``2dsphere`` indexes is ambiguous.
15+
16+
.. note::
17+
18+
If you do not specify the ``key``, and you have at most only one
19+
|first-geo-index| index and/or only one |first-geo-index| index,
20+
MongoDB looks first for a ``2d`` index to use. If a ``2d`` index
21+
does not exists, then MongoDB looks for a ``2dsphere`` index to use.

0 commit comments

Comments
 (0)