Pipeline Practice

MongoDB $setWindowFields

Calculate across an ordered window without collapsing documents.

Choose an optional partition, define the sort order, then add one or more window outputs. Unlike `$group`, the original document grain remains available after this stage.

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: Beyond Hard Mode.

Example pipeline syntax

{ $setWindowFields: {
  partitionBy: "$region",
  sortBy: { placedDate: 1 },
  output: { orderNumber: { $documentNumber: {} } }
} }