Returns an array whose elements are a generated sequence of numbers.
$rangegenerates the sequence from the specified starting number by successively incrementing the starting number by the specified step value up to but not including the end point.
An integer that specifies the start of the sequence. Can be any valid expression that resolves to an integer.
An integer that specifies the exclusive upper limit of the sequence. Can be any valid expression that resolves to an integer.
Optional. An integer that specifies the increment value. Can be any valid expression that resolves to a non-zero integer. Defaults to 1.
<end> arguments are required and must be integers. The
<non-zero step> argument is optional, and defaults to
1 if omitted.
The following example uses a collection called
distances that lists cities along with their distance in miles from San Francisco.
Documents in the
A bicyclist is planning to ride from San Francisco to each city listed in the collection and wants to stop and rest every 25 miles. The following aggregation pipeline operation uses the
$range operator to determine the stopping points for each trip.
The operation returns the following: