你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
适用对象: MongoDB vCore
运算符 $box
使用两个坐标对为地理空间查询定义矩形区域。 它可用于查找矩形地理边界内的位置。
语法
运算符的 $isArray
语法如下所示:
{
<location field>: {
$geoWithin: {
$box: [
[<lower_left_longitude>, <lower_left_latitude>],
[<upper_right_longitude>, <upper_right_latitude>]
]
}
}
}
参数
参数 | 类型 | DESCRIPTION |
---|---|---|
location field |
领域 | 包含地理空间数据的字段 |
lower_left |
数组 | 指定左下角的 [经度, 纬度] 数组 |
upper_right |
数组 | 指定右上角的 [经度, 纬度] 数组 |
示例:
stores
使用集合,让我们在矩形区域中查找存储:
db.stores.find({
location: {
$geoWithin: {
$box: [
[-142.0012, -51.3041], // Lower left corner (First Up Consultants location)
[123.3403, 70.1272] // Upper right corner (Northwind Traders location)
]
}
}
},
{
name: 1,
location: 1
})
此查询将返回属于这些坐标定义的矩形区域中的所有存储。