On this page本页内容
$box
¶Specifies a rectangle for a geospatial 为地理空间$geoWithin
query to return documents that are within the bounds of the rectangle, according to their point-based location data. $geoWithin
查询指定一个矩形,以根据基于点的位置数据返回矩形边界内的文档。When used with the 当与$box
operator, $geoWithin
returns documents based on grid coordinates and does not query for GeoJSON shapes.$box
运算符一起使用时,$geoWithin
根据网格坐标返回文档,并且不查询GeoJSON形状。
To use the 要使用$box
operator, you must specify the bottom left and top right corners of the rectangle in an array object:$box
运算符,必须指定数组对象中矩形的左下角和右上角:
Important
If you use longitude and latitude, specify longitude first.如果使用经度和纬度,请先指定经度。
The query calculates distances using flat (planar) geometry.该查询使用平面几何图形计算距离。
Applications can use 应用程序可以使用$box
without having a geospatial index. $box
,而无需地理空间索引。However, geospatial indexes support much faster queries than the unindexed equivalents.然而,地理空间索引支持的查询速度要比未索引的索引快得多。
Only the 2d geospatial index supports 只有2d地理空间索引支持$box
.$box
。
The following example query returns all documents that are within the box having points at: 下面的示例查询返回框中的所有文档,这些文档的点位于:[ 0 , 0 ]
, [ 0 , 100 ]
, [ 100 , 0 ]
, and [ 100 , 100 ]
.[0,0]
、[0,100]
、[100,0]
和[100,100]
。