Skip to main content

$subtract

The $subtract operator subtracts the second numeric value from the first numeric value.

Input

  • An array containing exactly two numeric values (minuend and subtrahend)

Output

  • The difference of the two input values (first - second)

Examples

Basic Subtraction

{
  "$subtract": [
    10,
    3
  ]
}
Result: 7

Field Value Subtraction

{
  "$subtract": [
    {
      "$input": "revenue"
    },
    {
      "$input": "expenses"
    }
  ]
}
Result: The difference between revenue and expenses fields

Decimal Subtraction

{
  "$subtract": [
    15.5,
    5.2
  ]
}
Result: 10.3