Evaluation operators

A number of different evaluation operators are supported.

Table 1. . Groupings - used with the $group task
Operator Description
$avg Returns the average value in the specified field. The $avg operator applies only to numeric data types.
$count Returns the number of selected documents.
$max Returns the highest value in the specified field. The $max operator applies to any data type that can be used for max (x) scalar function.
$min Returns the lowest value in the specified field. The $min operator applies to any data type that can be used for min(x) scalar function.
$sum Returns the sum of all the values in the specified field. The $sum operator applies only to numeric data types.
$first Returns the first value in the specified field.
$last Returns the last value in the specified field.
Table 2. . Arithmetic - applies to numeric data types
Operator Description
$add Takes an array of numbers and returns the sum of the values.
$divide Takes an array of two numbers and returns the value of the first number that is divided by the second number.
$inc Takes a number and increases its value by the specified number.
$mod Takes a list of two numbers and returns the remainder of the first number that is divided by the second number.
$multiply Takes a list of numbers and returns the value of multiplying the numbers.
$subtract Takes a list of two numbers and returns the difference of subtracting the first number from the second number.
Table 3. . String functions - applies to string data types
Operator Description
$concat Takes an array of strings and append the strings together into a concatenated string.
$strcasecmp Takes two strings and compares them. Returns an integer that reflects the comparison. If the returned integer is positive, the value of first string is greater than the value of the second string. If the returned integer is negative, the value of first string is less than the value of the second string. A return of 0 means both strings are of equal value.
$substr Takes a string and two numbers. The first number specifies the starting position and the second number specifies the length of the string to return.
$toLower Takes a string and returns it in all lowercase letters.
$toUpper Takes a string and returns it in all uppercase letters.
Table 4. . Date and Time - applies to date and time data types
Operator Description
$dayOfMonth Takes a date and returns the day of the month as a number between 1 and 31.
$dayOfWeek Takes a date and returns the day of the week as number between 1 and 7, where 1 represents Sunday and 7 represents Saturday.
$dayOfYear Takes a date and returns the day of the year as a number between 1 and 366.
$year Takes a date and returns the full value for the year.
$month Takes a date and returns the month as a number between 1 and 12.
$week Takes a date and returns the week as a number between 0 and 53. Week 1 is the first week that includes a Thursday.
$hour Takes a date and returns the hour as a number 0 and 23.
$minute Takes a date and returns the minute as a number between 0 and 59.
$second Takes a date and returns the second as a number between 0 and 60. The value of 60 occurs only for leap seconds.
$millisecond Takes a date and returns the millisecond as a number between 0 and 999.
Table 5. . Conditional expressions
Operator Description
$ifNull Takes two expressions and returns the first expression if it is a non-null value. Otherwise, it returns the second expression’s value.