Pipeline Practice

MongoDB $cond

Choose one of two values based on a condition.

The array form contains the condition first, the value returned when true second, and the value returned when false third.

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

Course use: Exercise 06.

Example pipeline syntax

{ $cond: [{ $gte: ["$total", 200] }, "high", "standard"] }