$center
On this page本页内容
Definition定义
$center
-
The$center
operator specifies a circle for a$geoWithin
query.$center
运算符为$geoWithin
查询指定一个圆。The query returns legacy coordinate pairs that are within the bounds of the circle. The operator does not return GeoJSON objects.查询返回圆边界内的旧坐标对。运算符不返回GeoJSON对象。To use the要使用$center
operator, specify an array that contains:$center
运算符,请指定一个包含以下内容的数组:The grid coordinates of the circle's center point, and圆中心点的栅格坐标,以及The circle's radius, as measured in the units used by the coordinate system.圆的半径,以坐标系使用的单位测量。
{
<location field>: {
$geoWithin: { $center: [ [ <x>, <y> ] , <radius> ] }
}
}ImportantIf you use longitude and latitude, specify longitude first.如果使用经度和纬度,请先指定经度。
Behavior行为
The query calculates distances using flat (planar) geometry.查询使用平面(平面)几何图形计算距离。
Applications can use 应用程序可以在没有地理空间索引的情况下使用$center
without having a geospatial index. However, geospatial indexes support much faster queries than the unindexed equivalents.$center
。但是,地理空间索引支持的查询速度比未编制索引的索引快得多。
Only the 2d geospatial index supports 只有$center
.2d
地理空间索引支持$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
:[ -74, 40.74 ]
为中心、半径为10
的圆内的文档:
db.places.find(
{ loc: { $geoWithin: { $center: [ [-74, 40.74], 10 ] } } }
)