-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
center.txt
64 lines (45 loc) · 1.41 KB
/
center.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
=======
$center
=======
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. query:: $center
The :query:`$center` operator specifies a circle for a
:query:`$geoWithin` query. The query returns legacy coordinate pairs
that are within the bounds of the circle. The operator does *not*
return GeoJSON objects.
To use the :query:`$center` operator, specify an array that
contains:
- The grid coordinates of the circle's center point, and
- The circle's radius, as measured in the units used by the
coordinate system.
.. code-block:: javascript
{
<location field>: {
$geoWithin: { $center: [ [ <x>, <y> ] , <radius> ] }
}
}
.. important::
If you use longitude and latitude, specify **longitude first**.
Behavior
--------
The query calculates distances using flat (planar) geometry.
.. |operator| replace:: :query:`$center`
.. include:: /includes/note-geospatial-index-must-exist.rst
Only the :doc:`2d </core/2d>` geospatial index supports
:query:`$center`.
Example
-------
The following example query returns all documents that have coordinates
that exist within the circle centered on ``[ -74, 40.74 ]`` and with a
radius of ``10``:
.. code-block:: javascript
db.places.find(
{ loc: { $geoWithin: { $center: [ [-74, 40.74], 10 ] } } }
)