Menu Docs

$center

$center

The $center operator specifies a circle for a $geoWithin query. The query returns legacy coordinate pairs that are within the bounds of the circle. The operator does não return GeoJSON objects.

To use the $center operator, specify an array that contains:

  • As coordenadas de grade do ponto central do círculo, e

  • The circle's radius, as measured in the units used by the coordinate system.

{
<location field>: {
$geoWithin: { $center: [ [ <x>, <y> ] , <radius> ] }
}
}

Importante

Se você utilizar longitude e latitude, especifique longitude primeiro.

A query calcula distâncias utilizando geometria plana (planar).

Os aplicativos podem utilizar o $center sem ter um índice geoespacial. No entanto, os índices geoespaciais suportam queries muito mais rápidas do que os equivalentes não indexados.

Only the 2d geospatial index supports $center.

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:

db.places.find(
{ loc: { $geoWithin: { $center: [ [-74, 40.74], 10 ] } } }
)