Pipeline Practice

MongoDB $set

Add or replace fields while keeping the rest of the document.

Use it when the next stage needs a calculated value but you still want every existing field to remain available. `$set` is an alias for `$addFields`.

Stages are the top-level steps in a pipeline. Each stage receives documents, changes the stream in one specific way, and passes its output to the next stage.

Course use: Exercises 04, 06, 12, and Hard Mode 13.

Example pipeline syntax

{ $set: { itemCount: { $sum: "$items.qty" } } }