$maxDistance
On this page本页内容
Definition定义
$maxDistance
-
The$maxDistance
operator constrains the results of a geospatial$near
or$nearSphere
query to the specified distance.$maxDistance
运算符将地理空间$near
或$nearSphere
查询的结果约束为指定的距离。The measuring units for the maximum distance are determined by the coordinate system in use.最大距离的测量单位由使用中的坐标系确定。For GeoJSON point objects, specify the distance in meters, not radians.对于GeoJSON点对象,以米为单位指定距离,而不是弧度。You must specify a non-negative number for必须为$maxDistance
.$maxDistance
指定一个非负数。The 2dsphere and 2d geospatial indexes both support$maxDistance
: .2dsphere
和2d
地理空间索引都支持$maxDistance
:。
Example实例
The following example query returns documents with location values that are 以下示例查询返回的文档的位置值从点10
or fewer units from the point [ -74 , 40 ]
.[ -74 , 40 ]
算起不超过10
个单位。
db.places.find( {
loc: { $near: [ -74 , 40 ], $maxDistance: 10 }
} )
MongoDB orders the results by their distance from MongoDB根据它们与[ -74 , 40 ]
. [ -74 , 40 ]
之间的距离对结果进行排序。The operation returns the first 100 results, unless you modify the query with the 除非使用cursor.limit()
method.cursor.limit()
方法修改查询,否则该操作将返回前100个结果。