对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

$centerSphere(查询谓词运算操作符)

$centerSphere

Defines a circle for a geospatial query that uses spherical geometry. The query returns documents that are within the bounds of the circle. You can use the $centerSphere operator on both GeoJSON objects and legacy coordinate pairs.

To use $centerSphere, specify an array that contains:

{
<location field>: {
$geoWithin: { $centerSphere: [ [ <x>, <y> ], <radius> ] }
}
}

重要

如果使用经度和纬度,请先指定经度。

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

Both 2dsphere and 2d geospatial indexes support $centerSphere.

以下示例查询网格坐标并返回经度 88 W 和纬度 30 N 的 10 英里半径内的所有文档。该查询通过除以近似地球赤道半径 3963.2 英里,将距离转换为弧度:

db.places.find( {
loc: { $geoWithin: { $centerSphere: [ [ -88, 30 ], 10/3963.2 ] } }
} )
给本页内容打分

在此页面上