Tsallaka zuwa abun ciki
Justice Tech School

$unwind

$unwind turns an array into one document per element so you can group or count items.

Example
db.posts.aggregate([
  { $unwind: "$tags" },
  { $group: { _id: "$tags", n: { $sum: 1 } } },
  { $sort: { n: -1 } }
])

Exercise

Split array elements.

{ $: "$tags" }

Quiz Test

What does $unwind do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.