diff --git a/source/reference/aggregation/cond.txt b/source/reference/aggregation/cond.txt index 432d7c7c1bb..50944cf8334 100644 --- a/source/reference/aggregation/cond.txt +++ b/source/reference/aggregation/cond.txt @@ -11,9 +11,26 @@ $cond (aggregation) .. code-block:: javascript { $cond: [ , , ] } - + Takes an array with three expressions, where the first expression evaluates to a Boolean value. If the first expression evaluates to true, :expression:`$cond` returns the value of the second expression. If the first expression evaluates to false, :expression:`$cond` evaluates and returns the third expression. + + + .. example:: + + The following aggregation returns the number of documents where the + amount field is greater than 100. + + .. code-block:: javascript + + db.accounts.aggregate([ + { + $group: { + _id: "totals", + totalAmount: { $sum: "$amount" }, + maxAmount: { $max: "$amount" }, + overMaxCount: { $sum: { $cond: [ { $gt: [ "$amount", 100 ] }, 1, 0 ] } }, + }} ]);