$add Fields
$add Fields
$addFields
Adds new fields to documents. $addFields outputs documents that contain all
existing fields from the input documents and newly added fields.
The $addFields stage is equivalent to a $project stage that explicitly specifies all
existing fields in the input documents and adds the new fields.
Note
You can also use the $set stage, which is an alias for $addFields.
We can do the following operations on $addFields
1. Add new Fields
2. Add new fields 2/multiple stages
3. Adding Fields in nested documents
4. Overwrite Existing documents
5. Replace one filed with another Field
6. Add element to the array
7. Remove fields.
7.Remove fields
You can use $addFields with the $$REMOVE variable to remove document fields.
After Before
Note:
$sum
$concatArrays
$$REMOVE