|
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