Pipeline Practice

MongoDB $dateTrunc

Normalize a date to the beginning of a time interval.

Truncating every event to the same unit creates reliable bucket keys for calendar reports. Specify timezone and week settings explicitly when the business definition requires them.

Expressions calculate a value inside a stage. They can read fields, compare values, perform arithmetic, or choose between two outcomes.

Course use: Beyond Hard Mode.

Example pipeline syntax

{ $dateTrunc: { date: "$placedDate", unit: "month" } }