Tsallaka zuwa abun ciki
Justice Tech School

$out and $merge

$out writes pipeline results to a new collection and $merge updates or inserts into an existing one. Use them to build reports.

Example
db.orders.aggregate([
  { $group: { _id: "$day", total: { $sum: "$amount" } } },
  { $merge: { into: "daily_totals", whenMatched: "replace" } }
])

Exercise

Save results.

{ $: { into: "daily" } }

Quiz Test

What does $merge do?

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