Para agentes de IA: um índice de documentação está disponível em https://www.mongodb.com/pt-br/docs/llms.txt — as versões de markdown de todas as páginas estão disponíveis anexando .md a qualquer caminho de URL.
Menu Docs

$box (operador de predicado de query)

$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. When used with the $box operator, $geoWithin returns documents based on grid coordinates and does not query for GeoJSON shapes.

To use the $box operator, you must specify the bottom left and top right corners of the rectangle in an array object:

{
<location field>: {
$geoWithin: {
$box: [
[ <bottom left coordinates> ],
[ <upper right coordinates> ]
]
}
}
}

Importante

Se você utilizar longitude e latitude, especifique longitude primeiro.

A query calcula distâncias utilizando geometria plana (planar).

Applications can use $box without having a geospatial index. However, geospatial indexes support much faster queries than the unindexed equivalents.

Only the 2d geospatial index supports $box.

A seguinte query de exemplo retorna todos os documentos que estão dentro da caixa com pontos em: [ 0 , 0 ], [ 0 , 100 ], [ 100 , 0 ] e [ 100 , 100 ].

db.places.find( {
loc: { $geoWithin: { $box: [ [ 0, 0 ], [ 100, 100 ] ] } }
} )
Avalie esta página