Q24: What does the $unwind stage do in an aggregation pipeline?
The $unwind stage deconstructs an array field from input documents to output a document for each element of the array. Each output document replaces the array with an individual element item. Commonly paired with $lookup to flatten joined arrays.
Key Takeaways
- Deconstructs array fields into individual document streams.
- Use
preserveNullAndEmptyArrays: trueto keep documents missing the array.
Knowledge Check
If a document contains an array of 3 items, how many output documents will $unwind produce for that document?