Skip to main content

$divide

The $divide operator divides the first numeric value by the second numeric value.

Input

  • An array containing exactly two numeric values (dividend and divisor)

Output

  • The quotient of the two input values (first / second)

Examples

Basic Division

{
  "$divide": [
    20,
    4
  ]
}
Result: 5.0

Field Value Division

{
  "$divide": [
    {
      "$input": "total_sales"
    },
    {
      "$input": "number_of_customers"
    }
  ]
}
Result: The average sales per customer

Decimal Division

{
  "$divide": [
    10.5,
    2
  ]
}
Result: 5.25

Division by Zero Error

{
  "$divide": [
    10,
    0
  ]
}
Result: Error (division by zero)