# 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: November 19, 2026

## [Arrays and Joins in a Pipeline](https://www.ask-codey.com/courses/mongodb-in-depth/topics/mongodb-arrays-and-joins-in-pipelines)

1. [$unwind: One Document per Array Item](https://www.ask-codey.com/lessons/mongodb-aggregation-unwind) (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.
2. [$lookup: Bringing in Related Documents](https://www.ask-codey.com/lessons/mongodb-aggregation-lookup) (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](https://www.ask-codey.com/courses/mongodb-in-depth/topics/mongodb-dates-in-pipelines)

1. [Reports by Day and Month: Dates in a Pipeline](https://www.ask-codey.com/lessons/mongodb-aggregation-reports-by-month) (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](https://www.ask-codey.com/courses/mongodb-in-depth/topics/mongodb-exercise-best-sellers-by-month)

1. [Exercise: Best Sellers by Month](https://www.ask-codey.com/lessons/exercise-mongodb-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.

Source: https://www.ask-codey.com/courses/mongodb-in-depth/chapters/unwind-lookup-and-dates-in-mongodb
