Skip to main content

$add

The $add operator adds two numeric values together.

Input

  • An array containing exactly two numeric values to add

Output

  • The sum of the two input values

Examples

Basic Addition

{
  "$add": [
    5,
    3
  ]
}
Result: 8

Field Value Addition

{
  "$add": [
    {
      "$input": "base_salary"
    },
    {
      "$input": "bonus"
    }
  ]
}
Result: The sum of base_salary and bonus fields

Mixed Number Types

{
  "$add": [
    10.5,
    2.3
  ]
}
Result: 12.8