Given a collection of events, aggregate their duration weekly. Fill gaps to contain every week since the earliest event.
Data Model
Users have meetings.
Duration Aggregated Weekly
The following aggregation matches any documents that belong to a user, groups and sorts them by year and week number, then counts and sums their durations.
Filling Gaps
The code above will miss any week without data. It’s easier to fill those in Ruby by iterating over weeks, starting with the current week and finishing with the week of the oldest available data.