MongoDB Arithmetic Operators

MongoDB arithmetic operators are a set of operators used to perform mathematical calculations. They can be used to calculate numerical fields in documents and return new calculated results. This page summarizes the arithmetic operators available in MongoDB.

  1. $abs

    The MongoDB $abs operator is used to calculate the absolute value of a specified field and is commonly used in various aggregation scenarios.
  2. $add

    The MongoDB $add operator can be used to add multiple numbers together and can accept any number of arguments.
  3. $ceil

    The $ceil operator is one of the mathematical operators in MongoDB, used to round a number up to the nearest integer.
  4. $divide

    In MongoDB, the $divide operator is used to divide a numeric field by another numeric field or constant.
  5. $exp

    The $exp operator is a mathematical operator in MongoDB that returns the value of the natural exponential function.
  6. $floor

    In MongoDB, the $floor operator is used for rounding down and returning the largest integer less than or equal to the specified number.
  7. $ln

    The MongoDB $ln operator is a mathematical operator in MongoDB used to calculate the natural logarithm (base e) of a number.
  8. $log

    The MongoDB $log operator is used to return the logarithm of a specified number.
  9. $log10

    The MongoDB $log10 operator is an aggregation pipeline operator used to calculate the base-10 logarithm of a given numeric value.
  10. $mod

    In MongoDB, the $mod operator is used to calculate the remainder of a given number and compare it with a specified value.
  11. $multiply

    The MongoDB $multiply is an aggregation operator used to calculate the product of two numbers in an expression and return the result.
  12. $pow

    In MongoDB, the $pow operator can be used to perform exponentiation on a number.
  13. $rand

    The $rand operator is a built-in operator in MongoDB used to generate a random number between [0,1).
  14. $round

    The $round is an aggregation operator in MongoDB that rounds a numeric field to a specified number of decimal places.
  15. $sqrt

    The $sqrt operator is a mathematical operator in MongoDB used to calculate the square root of a given number.
  16. $subtract

    The $subtract operator is a mathematical operator in MongoDB that calculates the difference between two numeric values and returns the result.
  17. $trunc

    The MongoDB $trunc operator is aggregation pipeline operator used to truncate a number to a specified number of decimal places or integer digits.