$unwind

noun

say it: “DOL-er un-WYND” /ˈdɑlər ʌnˈwaɪnd/

A MongoDB aggregation stage that turns a document with an array into one document per item of the array.

What does $unwind do?

$unwind turns a document with an array into one document per array element, so each element can be grouped or filtered.

db.recipes.aggregate([{ $unwind: '$tags' }, { $group: { _id: '$tags', count: { $sum: 1 } } }])

In a sentence

  • “$unwind on items turned one order with three items into three documents.”
  • “After $unwind, $group could count how often each product was sold.”

Level: Journeyman · More MongoDB terms at this level

Updated