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.
-
$abs
The MongoDB$abs
operator is used to calculate the absolute value of a specified field and is commonly used in various aggregation scenarios. -
$add
The MongoDB$add
operator can be used to add multiple numbers together and can accept any number of arguments. -
$ceil
The$ceil
operator is one of the mathematical operators in MongoDB, used to round a number up to the nearest integer. -
$divide
In MongoDB, the$divide
operator is used to divide a numeric field by another numeric field or constant. -
$exp
The$exp
operator is a mathematical operator in MongoDB that returns the value of the natural exponential function. -
$floor
In MongoDB, the$floor
operator is used for rounding down and returning the largest integer less than or equal to the specified number. -
$ln
The MongoDB$ln
operator is a mathematical operator in MongoDB used to calculate the natural logarithm (base e) of a number. -
$log
The MongoDB$log
operator is used to return the logarithm of a specified number. -
$log10
The MongoDB$log10
operator is an aggregation pipeline operator used to calculate the base-10 logarithm of a given numeric value. -
$mod
In MongoDB, the$mod
operator is used to calculate the remainder of a given number and compare it with a specified value. -
$multiply
The MongoDB$multiply
is an aggregation operator used to calculate the product of two numbers in an expression and return the result. -
$pow
In MongoDB, the$pow
operator can be used to perform exponentiation on a number. -
$rand
The$rand
operator is a built-in operator in MongoDB used to generate a random number between [0,1). -
$round
The$round
is an aggregation operator in MongoDB that rounds a numeric field to a specified number of decimal places. -
$sqrt
The$sqrt
operator is a mathematical operator in MongoDB used to calculate the square root of a given number. -
$subtract
The$subtract
operator is a mathematical operator in MongoDB that calculates the difference between two numeric values and returns the result. -
$trunc
The MongoDB$trunc
operator is aggregation pipeline operator used to truncate a number to a specified number of decimal places or integer digits.