- Reference >
- Operators >
- Query and Projection Operators >
- Geospatial Query Operators >
- $maxDistance
$maxDistance¶
On this page
Definition¶
-
$maxDistance
¶ The
$maxDistance
operator constrains the results of a geospatial$near
or$nearSphere
query to the specified distance. The measuring units for the maximum distance are determined by the coordinate system in use. For GeoJSON point object, specify the distance in meters, not radians.Changed in version 2.6: Specify a non-negative number for
$maxDistance
.The 2dsphere and 2d geospatial indexes both support
$maxDistance
: .
Example¶
The following example query returns documents with location values that
are 10
or fewer units from the point [ -74 , 40 ]
.
db.places.find( {
loc: { $near: [ -74 , 40 ], $maxDistance: 10 }
} )
MongoDB orders the results by their distance from [ -74 , 40 ]
.
The operation returns the first 100 results, unless you modify the
query with the cursor.limit()
method.