$box¶
-
$box¶ New in version 1.4.
The
$boxoperator specifies a rectangle for a geospatial$geoWithinquery. The query returns documents that are within the bounds of the rectangle, according to their point-based location data. The$boxoperator returns documents based on grid coordinates and does not query for GeoJSON shapes.The query calculates distances using flat (planar) geometry. The
2dgeospatial index supports the$boxoperator.To use the
$boxoperator, you must specify the bottom left and top right corners of the rectangle in an array object. Use the following syntax:Important
If you use longitude and latitude, specify longitude first.
The following example query returns all documents that are within the box having points at:
[ 0 , 0 ],[ 0 , 100 ],[ 100 , 0 ], and[ 100 , 100 ].Changed in version 2.2.3: Applications can use
$boxwithout having a geospatial index. However, geospatial indexes support much faster queries than the unindexed equivalents. Before 2.2.3, a geospatial index must exist on a field holding coordinates before using any of the geospatial query operators.