Exploring MongoDB Aggregation Stages: Code Examples and Applications - Part 1
$addFields:
db.collection.aggregate([
{ $addFields: { newField: { $sum: ["$field1", "$field2"] } } }
])
This example adds a new field "newField" to the documents in the collection and sets its value to the sum of the values of "field1" and "field...
akhilkumarpenugonda.hashnode.dev2 min read