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 not return GeoJSON objects.

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

  • 圆中心点的网格坐标,以及

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

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

重要

如果使用经度和纬度,请先指定经度。

查询用平面几何图形计算距离。

应用程序可以在没有地理空间索引的情况下使用 $center。但与未编制索引的同类查询相比,地理空间索引支持更快的查询速度。

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 ] } } }
)

在此页面上