On this page本页内容
$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 notreturn GeoJSON objects.运算符不返回GeoJSON对象。
To use the 要使用$center
operator, specify an array that contains:$center
运算符,请指定包含以下内容的数组:
{ <location field>: { $geoWithin: { $center: [ [ <x>, <y> ] , <radius> ] } } }
The query calculates distances using flat (planar) geometry.该查询使用平面(平面)几何图形计算距离。
Applications can use 应用程序可以使用$center
without having a geospatial index. $center
而无需地理空间索引。However, geospatial indexes support much faster queries than the unindexed equivalents.但是,地理空间索引支持的查询速度比未编制索引的等效查询快得多。
Only the 2d geospatial index supports 只有$center
.2d
地理空间索引支持$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
:[-74, 40.74]
为中心且半径为10
的圆内的所有文档:
db.places.find( { loc: { $geoWithin: { $center: [ [-74, 40.74], 10 ] } } } )