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