定义
$maxDistanceThe
$maxDistanceoperator constrains the results of a geospatial$nearor$nearSpherequery to the specified distance. 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. You must specify a non-negative number for$maxDistance.
例子
以下示例查询返回位置值距离点[ -74 , 40 ]不超过10个单位的文档。
db.places.find( { loc: { $near: [ -74 , 40 ], $maxDistance: 10 } } )
MongoDB 按与[ -74 , 40 ]的距离对结果进行排序。 除非您使用cursor.limit()方法修改查询,否则该操作将返回前 100 个结果。