Unwind, Lookup and Dates
Orders hold lists of items and point at customers. Turn each item into its own document with $unwind, bring in related documents with $lookup, and group sales by day, month and year.
Updated
Arrays and Joins in a Pipeline
- $unwind: One Document per Array Item (Journeyman): $unwind turns a document with an array into one document per item, so a pipeline can count, group and total the items themselves, such as the units of each product sold across every order.
- $lookup: Bringing in Related Documents (Journeyman): $lookup brings matching documents from another collection into each document of a pipeline, such as each order's customer, as an array you can unwind, and a lookup a screen needs on every read is a sign to embed or copy those fields instead.
Dates in a Pipeline
- Reports by Day and Month: Dates in a Pipeline (Journeyman): Dates stored as real dates can be matched by range and grouped by month or day with $year, $month and $dateToString, and the timezone option counts each order in the month it was where the shop is.
Exercise: Best Sellers by Month
- Exercise: Best Sellers by Month (Journeyman): Write five report pipelines for Riverbend Bike Shop's sales dashboard, from its top 5 products by units sold to its sales in each month of 2026 and each customer's spending with their name, and let the tests check the rows each one gives back.