A tumbling window divides a continuous stream into consecutive, nonoverlapping intervals of a chosen duration. Each document belongs to one window, making this a good fit for hourly sales totals, daily reports, or other results that must keep periods separate. For rolling analysis that reuses events across intervals, use a hopping window instead. section 15.2.2 section 15.5
In Atlas Stream Processing, $tumblingWindow bounds an otherwise continuous stream so stateful aggregation can run on each set of documents. A stream processor can have only one window stage. Place window-dependent stages such as $group inside the window’s pipeline, then send results to a stream with $emit or write them to an Atlas database with $merge. section 15.5 section 15.6.6
To build a ten-second aggregation in mongosh:
- Define $source and map its timestamp to the stream-processing time field. section 15.6.6
- Define the $group aggregation, then nest it in $tumblingWindow with an interval of 10 seconds; do not also put $group in the outer processor pipeline. section 15.6.6
- Define $merge as the Atlas database sink; create the processor with the outer stages in the order [$source, $tumblingWindow, $merge], then start it. section 15.6.6
let t = {
$tumblingWindow: {
interval: {
size: NumberInt(10),
unit: "second"
},
pipeline: [g]
}
}
The window configuration sets interval.size to 10, interval.unit to "second", and pipeline to [g], where g is the separately defined $group stage. section 15.6.6
AtlasStreamProcessing>sp.mongodbInAction.sample()
{
_id: 5,
max_temp: 24,
avg_watts: 48,
median_watts: 48,
max_watts: 53,
min_watts: 48,
_stream_meta: {
source: {
type: 'generated'
},
window: {
start: ISODate('2024-09-07T15:01:30.000Z'),
end: ISODate('2024-09-07T15:01:40.000Z')
}
}
}
AtlasStreamProcessing>
A sampled output document includes window start and end times, showing the ten-second interval associated with its aggregation. section 15.6.6


