Navigation
This version of the documentation is archived and no longer supported.

$box

$box

New in version 1.4.

The $box operator specifies a rectangular shape for the $within operator in geospatial queries. To use the $box operator, you must specify the bottom left and top right corners of the rectangle in an array object. Consider the following example:

db.collection.find( { loc: { $within: { $box: [ [0,0], [100,100] ] } } } )

This will return all the documents that are within the box having points at: [0,0], [0,100], [100,0], and [100,100].

Changed in version 2.2.3: Before 2.2.3, a geospatial index must exist on a field holding coordinates before using any of the geolocation query operators. After 2.2.3, applications may use geolocation query operators without having a geospatial index; however, geospatial indexes will support much faster geospatial queries than the unindexed equivalents.

Note

A geospatial index must exist on a field and the field must hold coordinates before you can use any of the geolocation query operators.

←   $and $center  →