A single element in an $aggregate update array. Each element is a plain object mapping field names to MongoDB aggregation expressions. You do not need to wrap the object in a $set — the API does that automatically.
$aggregate
$set
const update: UpdateAggregate = [ { avg_rating: { $avg: "$ratings" }, tier: { $cond: { if: { $gte: ["$avg_rating", 4.5] }, then: "platinum", else: "standard" } } }] Copy
const update: UpdateAggregate = [ { avg_rating: { $avg: "$ratings" }, tier: { $cond: { if: { $gte: ["$avg_rating", 4.5] }, then: "platinum", else: "standard" } } }]
A single element in an
$aggregateupdate array. Each element is a plain object mapping field names to MongoDB aggregation expressions. You do not need to wrap the object in a$set— the API does that automatically.