Aggregation Pipeline Operators
The aggregation pipeline operators construct expressions for use in the aggregation pipeline stages. The following are the list of Aggregation Pipeline Operators.
Arithmetic Expression Operators
It is used to perform arithmetic operations on numbers. Some arithmetic expression also supports data arithmetic.
$abs
The abs operator returns the absolute value of a number.
Syntax:
Example:
$add
It adds two or more numbers and a date. If one of the arguments is a date, then the date treats the other argument as milliseconds to add to the date.
Syntax:
Example:
$ceil
The ceil operator returns the smallest integer that is greater than or equal to the specified number.
Syntax:
Example:
$divide
It divides one or more numbers by another and returns the result.
Syntax:
Example:
$exp
The exp operator is used to raise Euler’s number to the specified exponent and returns the result.
Syntax:
Example:
$floor
The floor operator returns the greatest integer less than or equal to the specified number.
Syntax:
Example:
$ln
The ln operator calculates the natural logarithm of a number and returns the result as a double.
Syntax:
Example:
$log
The log operator calculates the log of a number for the specified base and returns the result as double.
Syntax:
Example:
$log10
The log10 operator calculates the log base 10 of a number and returns the result as a double.
Syntax:
Example:
$mod
The mod operator divides one number with another and returns the remainder.
Syntax:
Example:
$multiply
The multiply operator gives the product of two or more numbers.
Syntax:
Example:
$pow
The pow operator raises the number to the given exponent and returns the result.
Syntax:
Example:
$round
The round operator rounds a number to a whole integer or a specified decimal place.
Syntax:
Example:
$sqrt
The sqrt operator returns the square root of a positive number as double.
Syntax:
Example:
$subtract
The subtract operator subtracts two or more numbers to return the difference of the number.
Syntax:
Example:
$trunc
The trunc command deletes the data from the specified decimal place.
Syntax:
Example:
Array Expression Operator
$arrayElemAt
It returns the element at the specified array index.
Syntax:
Example:
$arrayToObject
The arrayToObject operator converts an array into a single document.
Syntax:
Example:
$concatArrays
The concatArrays operator joins the array to return the concatenated array.
Syntax:
Example:
$filter
The filter operator selects a subset of an array to return the result based on the specified condition.
Syntax:
Example:
$in
The in operator returns a boolean indicating that the specified value is in the array or not.
Syntax:
Example:
$indexOfArray
The indexOfArray operator searches the array for the occurrence of a specified value and returns the array index of the first occurrence.
Syntax:
Example:
$isArray
It determines and returns a Boolean value if the operand is an Array.
Syntax:
Example:
$map
The map operator attaches value to each item in an array and returns an array with the applied result.
Syntax:
Example:
$objectToArray
This operator converts a document to an array.
Syntax:
Example:
$range
The range operator returns an array whose elements are a generated sequence of numbers.
Syntax:
Example:
$reduce
The reduce operator applies an expression to each element in an array and combines them into a single value.
Syntax:
Example:
$reverseArray
It returns an array with the element in reverse order.
Syntax:
Example:
$size
The size operator counts and returns the total number of items in an array.
Syntax:
Example:
$slice
The slice operator results in a subset of an array.
Syntax:
Example:
$zip
The zip operator transposes an array so that the first element of the output array would be an array containing the first element of the first input array.
Syntax:
Example: