> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

# $maxDistance (query predicate operator)

## Definition

The [`$maxDistance`](https://www.mongodb.com/docs/manual/reference/operator/query/maxdistance.md#mongodb-query-op.-maxDistance) operator constrains the results of a geospatial [`$near`](https://www.mongodb.com/docs/manual/reference/operator/query/near.md#mongodb-query-op.-near) or [`$nearSphere`](https://www.mongodb.com/docs/manual/reference/operator/query/nearsphere.md#mongodb-query-op.-nearSphere) query to the specified distance. The measuring units for the maximum distance are determined by the coordinate system in use. For [GeoJSON](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-GeoJSON) point objects, specify the distance in meters, not radians. You must specify a non-negative number for [`$maxDistance`.](https://www.mongodb.com/docs/manual/reference/operator/query/maxdistance.md#mongodb-query-op.-maxDistance)

The [2dsphere](https://www.mongodb.com/docs/manual/core/indexes/index-types/geospatial/2dsphere.md#std-label-2dsphere-index) and [2d](https://www.mongodb.com/docs/manual/core/indexes/index-types/geospatial/2d.md#std-label-2d-index) geospatial indexes both support [`$maxDistance`](https://www.mongodb.com/docs/manual/reference/operator/query/maxdistance.md#mongodb-query-op.-maxDistance): .

## Example

The following example query returns documents with location values that are `10` or fewer units from the point `[ -74 , 40 ]`.

```javascript
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()`](https://www.mongodb.com/docs/manual/reference/method/cursor.limit.md#mongodb-method-cursor.limit) method.
