class Expr (View source)

Fluent interface for adding operators to aggregation stages.

Methods

$this
__call(string $method, array $args)

No description

$this
abs(mixed|Expr $number)

Returns the absolute value of a number.

$this
add($expression1, $expression2)

Adds numbers together or adds numbers and a date. If one of the arguments is a date, $add treats the other arguments as milliseconds to add to the date.

$this
addAnd(array|Expr $expression)

Adds one or more $and clauses to the current expression.

$this
addOr(array|Expr $expression)

Adds one or more $or clause to the current expression.

$this
addToSet(mixed|Expr $expression)

Returns an array of all unique values that results from applying an expression to each document in a group of documents that share the same group by key. Order of the elements in the output array is unspecified.

$this
allElementsTrue(mixed|Expr $expression)

Evaluates an array as a set and returns true if no element in the array is false. Otherwise, returns false. An empty array returns true.

$this
anyElementTrue(array|Expr $expression)

Evaluates an array as a set and returns true if any of the elements are true and false otherwise. An empty array returns false.

$this
arrayElemAt(mixed|Expr $array, mixed|Expr $index)

Returns the element at the specified array index.

$this
avg(mixed|Expr $expression)

Returns the average value of the numeric values that result from applying a specified expression to each document in a group of documents that share the same group by key. Ignores nun-numeric values.

$this
caseInternal(mixed|Expr $expression) deprecated

Adds a case statement for a branch of the $switch operator.

$this
ceil(mixed|Expr $number)

Returns the smallest integer greater than or equal to the specified number.

$this
cmp(mixed|Expr $expression1, mixed|Expr $expression2)

Compares two values and returns: -1 if the first value is less than the second.

$this
concat($expression1, $expression2)

Concatenates strings and returns the concatenated string.

$this
concatArrays($array1, $array2)

Concatenates arrays to return the concatenated array.

$this
cond(mixed|Expr $if, mixed|Expr $then, mixed|Expr $else)

Evaluates a boolean expression to return one of the two specified return expressions.

static string|array
convertExpression(mixed|Expr $expression)

Converts an expression object into an array, recursing into nested items

mixed
ensureArray(mixed|Expr $expression) deprecated

Ensures an array or operator expression is converted to an array.

$this
dateToString(string $format, mixed|Expr $expression)

Converts a date object to a string according to a user-specified format.

$this
dayOfMonth(mixed|Expr $expression)

Returns the day of the month for a date as a number between 1 and 31.

$this
dayOfWeek(mixed|Expr $expression)

Returns the day of the week for a date as a number between 1 (Sunday) and 7 (Saturday).

$this
dayOfYear(mixed|Expr $expression)

Returns the day of the year for a date as a number between 1 and 366.

$this
defaultInternal(mixed|Expr $expression) deprecated

Adds a default statement for the current $switch operator.

$this
divide(mixed|Expr $expression1, mixed|Expr $expression2)

Divides one number by another and returns the result. The first argument is divided by the second argument.

$this
eq(mixed|Expr $expression1, mixed|Expr $expression2)

Compares two values and returns whether the are equivalent.

$this
exp(mixed|Expr $exponent)

Raises Euler’s number to the specified exponent and returns the result.

expr()

Returns a new expression object

$this
expression(mixed|Expr $value)

Allows any expression to be used as a field value.

$this
field(string $fieldName)

Set the current field for building the expression.

$this
filter(mixed|Expr $input, mixed|Expr $as, mixed|Expr $cond)

Selects a subset of the array to return based on the specified condition.

$this
first(mixed|Expr $expression)

Returns the value that results from applying an expression to the first document in a group of documents that share the same group by key. Only meaningful when documents are in a defined order.

$this
floor(mixed|Expr $number)

Returns the largest integer less than or equal to the specified number.

array
getExpression()

No description

$this
gt(mixed|Expr $expression1, mixed|Expr $expression2)

Compares two values and returns: true when the first value is greater than the second value.

$this
gte(mixed|Expr $expression1, mixed|Expr $expression2)

Compares two values and returns: true when the first value is greater than or equivalent to the second value.

$this
hour(mixed|Expr $expression)

Returns the hour portion of a date as a number between 0 and 23.

$this
ifNull(mixed|Expr $expression, mixed|Expr $replacementExpression)

Evaluates an expression and returns the value of the expression if the expression evaluates to a non-null value. If the expression evaluates to a null value, including instances of undefined values or missing fields, returns the value of the replacement expression.

$this
in(mixed|Expr $expression, mixed|Expr $arrayExpression)

Returns a boolean indicating whether a specified value is in an array.

$this
indexOfArray(mixed|Expr $arrayExpression, mixed|Expr $searchExpression, mixed|Expr $start = null, mixed|Expr $end = null)

Searches an array for an occurence of a specified value and returns the array index (zero-based) of the first occurence. If the value is not found, returns -1.

$this
indexOfBytes(mixed|Expr $stringExpression, mixed|Expr $substringExpression, int|null $start = null, int|null $end = null)

Searches a string for an occurence of a substring and returns the UTF-8 byte index (zero-based) of the first occurence. If the substring is not found, returns -1.

$this
indexOfCP(mixed|Expr $stringExpression, mixed|Expr $substringExpression, int|null $start = null, int|null $end = null)

Searches a string for an occurence of a substring and returns the UTF-8 code point index (zero-based) of the first occurence. If the substring is not found, returns -1.

$this
isArray(mixed|Expr $expression)

Determines if the operand is an array. Returns a boolean.

$this
isoDayOfWeek(mixed|Expr $expression)

Returns the weekday number in ISO 8601 format, ranging from 1 (for Monday) to 7 (for Sunday).

$this
isoWeek(mixed|Expr $expression)

Returns the week number in ISO 8601 format, ranging from 1 to 53.

$this
isoWeekYear(mixed|Expr $expression)

Returns the year number in ISO 8601 format.

$this
last(mixed|Expr $expression)

Returns the value that results from applying an expression to the last document in a group of documents that share the same group by a field.

$this
let(mixed|Expr $vars, mixed|Expr $in)

Binds variables for use in the specified expression, and returns the result of the expression.

$this
literal(mixed|Expr $value)

Returns a value without parsing. Use for values that the aggregation pipeline may interpret as an expression.

$this
ln(mixed|Expr $number)

Calculates the natural logarithm ln (i.e loge) of a number and returns the result as a double.

$this
log(mixed|Expr $number, mixed|Expr $base)

Calculates the log of a number in the specified base and returns the result as a double.

$this
log10(mixed|Expr $number)

Calculates the log base 10 of a number and returns the result as a double.

$this
lt(mixed|Expr $expression1, mixed|Expr $expression2)

Compares two values and returns: true when the first value is less than the second value.

$this
lte(mixed|Expr $expression1, mixed|Expr $expression2)

Compares two values and returns: true when the first value is less than or equivalent to the second value.

$this
map(mixed|Expr $input, string $as, mixed|Expr $in)

Applies an expression to each item in an array and returns an array with the applied results.

$this
max(mixed|Expr $expression)

Returns the highest value that results from applying an expression to each document in a group of documents that share the same group by key.

$this
meta($metaDataKeyword)

Returns the metadata associated with a document in a pipeline operations.

$this
millisecond(mixed|Expr $expression)

Returns the millisecond portion of a date as an integer between 0 and 999.

$this
min(mixed|Expr $expression)

Returns the lowest value that results from applying an expression to each document in a group of documents that share the same group by key.

$this
minute(mixed|Expr $expression)

Returns the minute portion of a date as a number between 0 and 59.

$this
mod(mixed|Expr $expression1, mixed|Expr $expression2)

Divides one number by another and returns the remainder. The first argument is divided by the second argument.

$this
month(mixed|Expr $expression)

Returns the month of a date as a number between 1 and 12.

$this
multiply($expression1, $expression2)

Multiplies numbers together and returns the result.

$this
ne(mixed|Expr $expression1, mixed|Expr $expression2)

Compares two values and returns: true when the values are not equivalent.

$this
not(mixed|Expr $expression)

Evaluates a boolean and returns the opposite boolean value.

$this
pow(mixed|Expr $number, mixed|Expr $exponent)

Raises a number to the specified exponent and returns the result.

$this
push(mixed|Expr $expression)

Returns an array of all values that result from applying an expression to each document in a group of documents that share the same group by key.

$this
range(mixed|Expr $start, mixed|Expr $end, mixed|Expr $step = 1)

Returns an array whose elements are a generated sequence of numbers.

$this
reduce(mixed|Expr $input, mixed|Expr $initialValue, mixed|Expr $in)

Applies an expression to each element in an array and combines them into a single value.

$this
reverseArray(mixed|Expr $expression)

Accepts an array expression as an argument and returns an array with the elements in reverse order.

$this
second(mixed|Expr $expression)

Returns the second portion of a date as a number between 0 and 59, but can be 60 to account for leap seconds.

$this
setDifference(mixed|Expr $expression1, mixed|Expr $expression2)

Takes two sets and returns an array containing the elements that only exist in the first set.

$this
setEquals($expression1, $expression2)

Compares two or more arrays and returns true if they have the same distinct elements and false otherwise.

$this
setIntersection($expression1, $expression2)

Takes two or more arrays and returns an array that contains the elements that appear in every input array.

$this
setIsSubset(mixed|Expr $expression1, mixed|Expr $expression2)

Takes two arrays and returns true when the first array is a subset of the second, including when the first array equals the second array, and false otherwise.

$this
setUnion($expression1, $expression2)

Takes two or more arrays and returns an array containing the elements that appear in any input array.

$this
size(mixed|Expr $expression)

Counts and returns the total the number of items in an array.

$this
slice(mixed|Expr $array, mixed|Expr $n, mixed|Expr|null $position = null)

Returns a subset of an array.

$this
split(mixed|Expr $string, mixed|Expr $delimiter)

Divides a string into an array of substrings based on a delimiter.

$this
sqrt(mixed|Expr $expression)

Calculates the square root of a positive number and returns the result as a double.

$this
stdDevPop($expression1)

Calculates the population standard deviation of the input values.

$this
stdDevSamp($expression1)

Calculates the sample standard deviation of the input values.

$this
strcasecmp(mixed|Expr $expression1, mixed|Expr $expression2)

Performs case-insensitive comparison of two strings. Returns 1 if first string is “greater than” the second string.

$this
strLenBytes(mixed|Expr $string)

Returns the number of UTF-8 encoded bytes in the specified string.

$this
strLenCP(mixed|Expr $string)

Returns the number of UTF-8 code points in the specified string.

$this
substr(mixed|Expr $string, mixed|Expr $start, mixed|Expr $length)

Returns a substring of a string, starting at a specified index position and including the specified number of characters. The index is zero-based.

$this
substrBytes(mixed|Expr $string, mixed|Expr $start, mixed|Expr $count)

Returns the substring of a string.

$this
substrCP(mixed|Expr $string, mixed|Expr $start, mixed|Expr $count)

Returns the substring of a string.

$this
subtract(mixed|Expr $expression1, mixed|Expr $expression2)

Subtracts two numbers to return the difference. The second argument is subtracted from the first argument.

$this
sum(mixed|Expr $expression)

Calculates and returns the sum of all the numeric values that result from applying a specified expression to each document in a group of documents that share the same group by key. Ignores nun-numeric values.

$this
switchInternal() deprecated

Evaluates a series of case expressions. When it finds an expression which evaluates to true, $switch executes a specified expression and breaks out of the control flow.

$this
thenInternal(mixed|Expr $expression) deprecated

Adds a case statement for the current branch of the $switch operator.

$this
toLower(mixed|Expr $expression)

Converts a string to lowercase, returning the result.

$this
toUpper(mixed|Expr $expression)

Converts a string to uppercase, returning the result.

$this
trunc(mixed|Expr $number)

Truncates a number to its integer.

$this
type(mixed|Expr $expression)

Returns a string that specifies the BSON type of the argument.

$this
week(mixed|Expr $expression)

Returns the week of the year for a date as a number between 0 and 53.

$this
year(mixed|Expr $expression)

Returns the year portion of a date.

$this
zip(mixed|Expr $inputs, bool|null $useLongestLength = null, mixed|Expr|null $defaults = null)

Transposes an array of input arrays so that the first element of the output array would be an array containing, the first element of the first input array, the first element of the second input array, etc.

Details

$this __call(string $method, array $args)

Parameters

string $method
array $args

Return Value

$this

$this abs(mixed|Expr $number)

Returns the absolute value of a number.

The argument can be any valid expression as long as it resolves to a number.

Parameters

mixed|Expr $number

Return Value

$this

See also

https://docs.mongodb.org/manual/reference/operator/aggregation/abs/

$this add($expression1, $expression2)

Adds numbers together or adds numbers and a date. If one of the arguments is a date, $add treats the other arguments as milliseconds to add to the date.

The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date.

Parameters

$expression1
$expression2

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/add/

$this addAnd(array|Expr $expression)

Adds one or more $and clauses to the current expression.

Parameters

array|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/and/

$this addOr(array|Expr $expression)

Adds one or more $or clause to the current expression.

Parameters

array|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/or/

$this addToSet(mixed|Expr $expression)

Returns an array of all unique values that results from applying an expression to each document in a group of documents that share the same group by key. Order of the elements in the output array is unspecified.

AddToSet is an accumulator operation only available in the group stage.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/addToSet/

$this allElementsTrue(mixed|Expr $expression)

Evaluates an array as a set and returns true if no element in the array is false. Otherwise, returns false. An empty array returns true.

The expression must resolve to an array.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/allElementsTrue/

$this anyElementTrue(array|Expr $expression)

Evaluates an array as a set and returns true if any of the elements are true and false otherwise. An empty array returns false.

The expression must resolve to an array.

Parameters

array|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/anyElementTrue/

$this arrayElemAt(mixed|Expr $array, mixed|Expr $index)

Returns the element at the specified array index.

The expression can be any valid expression as long as it resolves to an array. The expression can be any valid expression as long as it resolves to an integer.

Parameters

mixed|Expr $array
mixed|Expr $index

Return Value

$this

See also

https://docs.mongodb.org/manual/reference/operator/aggregation/arrayElemAt/

$this avg(mixed|Expr $expression)

Returns the average value of the numeric values that result from applying a specified expression to each document in a group of documents that share the same group by key. Ignores nun-numeric values.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/avg/

protected $this caseInternal(mixed|Expr $expression) deprecated

deprecated Method will be renamed to "case" in next major version

Adds a case statement for a branch of the $switch operator.

Requires {@link switch()} to be called first. The argument can be any valid expression that resolves to a boolean. If the result is not a boolean, it is coerced to a boolean value.

Parameters

mixed|Expr $expression

Return Value

$this

$this ceil(mixed|Expr $number)

Returns the smallest integer greater than or equal to the specified number.

The expression can be any valid expression as long as it resolves to a number.

Parameters

mixed|Expr $number

Return Value

$this

See also

https://docs.mongodb.org/manual/reference/operator/aggregation/ceil/

$this cmp(mixed|Expr $expression1, mixed|Expr $expression2)

Compares two values and returns: -1 if the first value is less than the second.

1 if the first value is greater than the second. 0 if the two values are equivalent.

Parameters

mixed|Expr $expression1
mixed|Expr $expression2

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/cmp/

$this concat($expression1, $expression2)

Concatenates strings and returns the concatenated string.

The arguments can be any valid expression as long as they resolve to strings. If the argument resolves to a value of null or refers to a field that is missing, $concat returns null.

Parameters

$expression1
$expression2

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/concat/

$this concatArrays($array1, $array2)

Concatenates arrays to return the concatenated array.

The expressions can be any valid expression as long as they resolve to an array.

Parameters

$array1
$array2

Return Value

$this

See also

https://docs.mongodb.org/manual/reference/operator/aggregation/concatArrays/

$this cond(mixed|Expr $if, mixed|Expr $then, mixed|Expr $else)

Evaluates a boolean expression to return one of the two specified return expressions.

The arguments can be any valid expression.

Parameters

mixed|Expr $if
mixed|Expr $then
mixed|Expr $else

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/cond/

static string|array convertExpression(mixed|Expr $expression)

Converts an expression object into an array, recursing into nested items

For expression objects, it calls getExpression on the expression object. For arrays, it recursively calls itself for each array item. Other values are returned directly.

Parameters

mixed|Expr $expression

Return Value

string|array

protected mixed ensureArray(mixed|Expr $expression) deprecated

deprecated Deprecated in favor of convertExpression

Ensures an array or operator expression is converted to an array.

Parameters

mixed|Expr $expression

Return Value

mixed

$this dateToString(string $format, mixed|Expr $expression)

Converts a date object to a string according to a user-specified format.

The format string can be any string literal, containing 0 or more format specifiers. The date argument can be any expression as long as it resolves to a date.

Parameters

string $format
mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/dateToString/

$this dayOfMonth(mixed|Expr $expression)

Returns the day of the month for a date as a number between 1 and 31.

The argument can be any expression as long as it resolves to a date.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/dayOfMonth/

$this dayOfWeek(mixed|Expr $expression)

Returns the day of the week for a date as a number between 1 (Sunday) and 7 (Saturday).

The argument can be any expression as long as it resolves to a date.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/dayOfWeek/

$this dayOfYear(mixed|Expr $expression)

Returns the day of the year for a date as a number between 1 and 366.

The argument can be any expression as long as it resolves to a date.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/dayOfYear/

protected $this defaultInternal(mixed|Expr $expression) deprecated

deprecated Method will be renamed to "default" in next major version

Adds a default statement for the current $switch operator.

Requires {@link switch()} to be called first. The argument can be any valid expression.

Note: if no default is specified and no branch evaluates to true, the $switch operator throws an error.

Parameters

mixed|Expr $expression

Return Value

$this

$this divide(mixed|Expr $expression1, mixed|Expr $expression2)

Divides one number by another and returns the result. The first argument is divided by the second argument.

The arguments can be any valid expression as long as the resolve to numbers.

Parameters

mixed|Expr $expression1
mixed|Expr $expression2

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/divide/

$this eq(mixed|Expr $expression1, mixed|Expr $expression2)

Compares two values and returns whether the are equivalent.

Parameters

mixed|Expr $expression1
mixed|Expr $expression2

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/eq/

$this exp(mixed|Expr $exponent)

Raises Euler’s number to the specified exponent and returns the result.

The expression can be any valid expression as long as it resolves to a number.

Parameters

mixed|Expr $exponent

Return Value

$this

See also

https://docs.mongodb.org/manual/reference/operator/aggregation/exp/

Expr expr()

Returns a new expression object

Return Value

Expr

$this expression(mixed|Expr $value)

Allows any expression to be used as a field value.

$this field(string $fieldName)

Set the current field for building the expression.

Parameters

string $fieldName

Return Value

$this

$this filter(mixed|Expr $input, mixed|Expr $as, mixed|Expr $cond)

Selects a subset of the array to return based on the specified condition.

Returns an array with only those elements that match the condition. The returned elements are in the original order.

Parameters

mixed|Expr $input
mixed|Expr $as
mixed|Expr $cond

Return Value

$this

See also

https://docs.mongodb.org/manual/reference/operator/aggregation/filter/

$this first(mixed|Expr $expression)

Returns the value that results from applying an expression to the first document in a group of documents that share the same group by key. Only meaningful when documents are in a defined order.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/first/

$this floor(mixed|Expr $number)

Returns the largest integer less than or equal to the specified number.

The expression can be any valid expression as long as it resolves to a number.

Parameters

mixed|Expr $number

Return Value

$this

See also

https://docs.mongodb.org/manual/reference/operator/aggregation/floor/

array getExpression()

Return Value

array

$this gt(mixed|Expr $expression1, mixed|Expr $expression2)

Compares two values and returns: true when the first value is greater than the second value.

false when the first value is less than or equivalent to the second value.

Parameters

mixed|Expr $expression1
mixed|Expr $expression2

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/gt/

$this gte(mixed|Expr $expression1, mixed|Expr $expression2)

Compares two values and returns: true when the first value is greater than or equivalent to the second value.

false when the first value is less than the second value.

Parameters

mixed|Expr $expression1
mixed|Expr $expression2

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/gte/

$this hour(mixed|Expr $expression)

Returns the hour portion of a date as a number between 0 and 23.

The argument can be any expression as long as it resolves to a date.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/hour/

$this ifNull(mixed|Expr $expression, mixed|Expr $replacementExpression)

Evaluates an expression and returns the value of the expression if the expression evaluates to a non-null value. If the expression evaluates to a null value, including instances of undefined values or missing fields, returns the value of the replacement expression.

The arguments can be any valid expression.

Parameters

mixed|Expr $expression
mixed|Expr $replacementExpression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/ifNull/

$this in(mixed|Expr $expression, mixed|Expr $arrayExpression)

Returns a boolean indicating whether a specified value is in an array.

Unlike the $in query operator, the aggregation $in operator does not support matching by regular expressions.

Parameters

mixed|Expr $expression
mixed|Expr $arrayExpression

Return Value

$this

See also

https://docs.mongodb.com/manual/reference/operator/aggregation/in/

$this indexOfArray(mixed|Expr $arrayExpression, mixed|Expr $searchExpression, mixed|Expr $start = null, mixed|Expr $end = null)

Searches an array for an occurence of a specified value and returns the array index (zero-based) of the first occurence. If the value is not found, returns -1.

Parameters

mixed|Expr $arrayExpression Can be any valid expression as long as it resolves to an array.
mixed|Expr $searchExpression Can be any valid expression.
mixed|Expr $start Optional. An integer, or a number that can be represented as integers (such as 2.0), that specifies the starting index position for the search. Can be any valid expression that resolves to a non-negative integral number.
mixed|Expr $end An integer, or a number that can be represented as integers (such as 2.0), that specifies the ending index position for the search. Can be any valid expression that resolves to a non-negative integral number.

Return Value

$this

See also

https://docs.mongodb.com/manual/reference/operator/aggregation/indexOfArray/

$this indexOfBytes(mixed|Expr $stringExpression, mixed|Expr $substringExpression, int|null $start = null, int|null $end = null)

Searches a string for an occurence of a substring and returns the UTF-8 byte index (zero-based) of the first occurence. If the substring is not found, returns -1.

Parameters

mixed|Expr $stringExpression Can be any valid expression as long as it resolves to a string.
mixed|Expr $substringExpression Can be any valid expression as long as it resolves to a string.
int|null $start An integral number that specifies the starting index position for the search. Can be any valid expression that resolves to a non-negative integral number.
int|null $end An integral number that specifies the ending index position for the search. Can be any valid expression that resolves to a non-negative integral number.

Return Value

$this

See also

https://docs.mongodb.com/manual/reference/operator/aggregation/indexOfBytes/

$this indexOfCP(mixed|Expr $stringExpression, mixed|Expr $substringExpression, int|null $start = null, int|null $end = null)

Searches a string for an occurence of a substring and returns the UTF-8 code point index (zero-based) of the first occurence. If the substring is not found, returns -1.

Parameters

mixed|Expr $stringExpression Can be any valid expression as long as it resolves to a string.
mixed|Expr $substringExpression Can be any valid expression as long as it resolves to a string.
int|null $start An integral number that specifies the starting index position for the search. Can be any valid expression that resolves to a non-negative integral number.
int|null $end An integral number that specifies the ending index position for the search. Can be any valid expression that resolves to a non-negative integral number.

Return Value

$this

See also

https://docs.mongodb.com/manual/reference/operator/aggregation/indexOfCP/

$this isArray(mixed|Expr $expression)

Determines if the operand is an array. Returns a boolean.

The can be any valid expression.

Parameters

mixed|Expr $expression

Return Value

$this

See also

https://docs.mongodb.org/manual/reference/operator/aggregation/isArray/

$this isoDayOfWeek(mixed|Expr $expression)

Returns the weekday number in ISO 8601 format, ranging from 1 (for Monday) to 7 (for Sunday).

The argument can be any expression as long as it resolves to a date.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/isoDayOfWeek/

$this isoWeek(mixed|Expr $expression)

Returns the week number in ISO 8601 format, ranging from 1 to 53.

Week numbers start at 1 with the week (Monday through Sunday) that contains the year’s first Thursday.

The argument can be any expression as long as it resolves to a date.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/isoWeek/

$this isoWeekYear(mixed|Expr $expression)

Returns the year number in ISO 8601 format.

The year starts with the Monday of week 1 (ISO 8601) and ends with the Sunday of the last week (ISO 8601).

The argument can be any expression as long as it resolves to a date.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/isoWeek/

$this last(mixed|Expr $expression)

Returns the value that results from applying an expression to the last document in a group of documents that share the same group by a field.

Only meaningful when documents are in a defined order.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/last/

$this let(mixed|Expr $vars, mixed|Expr $in)

Binds variables for use in the specified expression, and returns the result of the expression.

Parameters

mixed|Expr $vars Assignment block for the variables accessible in the in expression. To assign a variable, specify a string for the variable name and assign a valid expression for the value.
mixed|Expr $in The expression to evaluate.

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/let/

$this literal(mixed|Expr $value)

Returns a value without parsing. Use for values that the aggregation pipeline may interpret as an expression.

Parameters

mixed|Expr $value

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/literal/

$this ln(mixed|Expr $number)

Calculates the natural logarithm ln (i.e loge) of a number and returns the result as a double.

The expression can be any valid expression as long as it resolves to a non-negative number.

Parameters

mixed|Expr $number

Return Value

$this

See also

https://docs.mongodb.org/manual/reference/operator/aggregation/log/

$this log(mixed|Expr $number, mixed|Expr $base)

Calculates the log of a number in the specified base and returns the result as a double.

The expression can be any valid expression as long as it resolves to a non-negative number. The expression can be any valid expression as long as it resolves to a positive number greater than 1.

Parameters

mixed|Expr $number
mixed|Expr $base

Return Value

$this

See also

https://docs.mongodb.org/manual/reference/operator/aggregation/log/

$this log10(mixed|Expr $number)

Calculates the log base 10 of a number and returns the result as a double.

The expression can be any valid expression as long as it resolves to a non-negative number.

Parameters

mixed|Expr $number

Return Value

$this

See also

https://docs.mongodb.org/manual/reference/operator/aggregation/log10/

$this lt(mixed|Expr $expression1, mixed|Expr $expression2)

Compares two values and returns: true when the first value is less than the second value.

false when the first value is greater than or equivalent to the second value.

Parameters

mixed|Expr $expression1
mixed|Expr $expression2

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/lt/

$this lte(mixed|Expr $expression1, mixed|Expr $expression2)

Compares two values and returns: true when the first value is less than or equivalent to the second value.

false when the first value is greater than the second value.

Parameters

mixed|Expr $expression1
mixed|Expr $expression2

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/lte/

$this map(mixed|Expr $input, string $as, mixed|Expr $in)

Applies an expression to each item in an array and returns an array with the applied results.

Parameters

mixed|Expr $input An expression that resolves to an array.
string $as The variable name for the items in the input array. The in expression accesses each item in the input array by this variable.
mixed|Expr $in The expression to apply to each item in the input array. The expression accesses the item by its variable name.

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/map/

$this max(mixed|Expr $expression)

Returns the highest value that results from applying an expression to each document in a group of documents that share the same group by key.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/max/

$this meta($metaDataKeyword)

Returns the metadata associated with a document in a pipeline operations.

Parameters

$metaDataKeyword

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/meta/

$this millisecond(mixed|Expr $expression)

Returns the millisecond portion of a date as an integer between 0 and 999.

The argument can be any expression as long as it resolves to a date.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/millisecond/

$this min(mixed|Expr $expression)

Returns the lowest value that results from applying an expression to each document in a group of documents that share the same group by key.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/min/

$this minute(mixed|Expr $expression)

Returns the minute portion of a date as a number between 0 and 59.

The argument can be any expression as long as it resolves to a date.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/minute/

$this mod(mixed|Expr $expression1, mixed|Expr $expression2)

Divides one number by another and returns the remainder. The first argument is divided by the second argument.

The arguments can be any valid expression as long as they resolve to numbers.

Parameters

mixed|Expr $expression1
mixed|Expr $expression2

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/mod/

$this month(mixed|Expr $expression)

Returns the month of a date as a number between 1 and 12.

The argument can be any expression as long as it resolves to a date.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/month/

$this multiply($expression1, $expression2)

Multiplies numbers together and returns the result.

The arguments can be any valid expression as long as they resolve to numbers.

Parameters

$expression1
$expression2

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/multiply/

$this ne(mixed|Expr $expression1, mixed|Expr $expression2)

Compares two values and returns: true when the values are not equivalent.

false when the values are equivalent.

Parameters

mixed|Expr $expression1
mixed|Expr $expression2

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/ne/

$this not(mixed|Expr $expression)

Evaluates a boolean and returns the opposite boolean value.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/not/

$this pow(mixed|Expr $number, mixed|Expr $exponent)

Raises a number to the specified exponent and returns the result.

The expression can be any valid expression as long as it resolves to a non-negative number. The expression can be any valid expression as long as it resolves to a number.

Parameters

mixed|Expr $number
mixed|Expr $exponent

Return Value

$this

See also

https://docs.mongodb.org/manual/reference/operator/aggregation/pow/

$this push(mixed|Expr $expression)

Returns an array of all values that result from applying an expression to each document in a group of documents that share the same group by key.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/push/

$this range(mixed|Expr $start, mixed|Expr $end, mixed|Expr $step = 1)

Returns an array whose elements are a generated sequence of numbers.

$range generates the sequence from the specified starting number by successively incrementing the starting number by the specified step value up to but not including the end point.

Parameters

mixed|Expr $start An integer that specifies the start of the sequence. Can be any valid expression that resolves to an integer.
mixed|Expr $end An integer that specifies the exclusive upper limit of the sequence. Can be any valid expression that resolves to an integer.
mixed|Expr $step Optional. An integer that specifies the increment value. Can be any valid expression that resolves to a non-zero integer. Defaults to 1.

Return Value

$this

See also

https://docs.mongodb.com/manual/reference/operator/aggregation/range/

$this reduce(mixed|Expr $input, mixed|Expr $initialValue, mixed|Expr $in)

Applies an expression to each element in an array and combines them into a single value.

Parameters

mixed|Expr $input Can be any valid expression that resolves to an array.
mixed|Expr $initialValue The initial cumulative value set before in is applied to the first element of the input array.
mixed|Expr $in A valid expression that $reduce applies to each element in the input array in left-to-right order. Wrap the input value with $reverseArray to yield the equivalent of applying the combining expression from right-to-left.

Return Value

$this

See also

https://docs.mongodb.com/manual/reference/operator/aggregation/reduce/

$this reverseArray(mixed|Expr $expression)

Accepts an array expression as an argument and returns an array with the elements in reverse order.

Parameters

mixed|Expr $expression

Return Value

$this

See also

https://docs.mongodb.com/manual/reference/operator/aggregation/reverseArray/

$this second(mixed|Expr $expression)

Returns the second portion of a date as a number between 0 and 59, but can be 60 to account for leap seconds.

The argument can be any expression as long as it resolves to a date.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/second/

$this setDifference(mixed|Expr $expression1, mixed|Expr $expression2)

Takes two sets and returns an array containing the elements that only exist in the first set.

The arguments can be any valid expression as long as they each resolve to an array.

Parameters

mixed|Expr $expression1
mixed|Expr $expression2

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/setDifference/

$this setEquals($expression1, $expression2)

Compares two or more arrays and returns true if they have the same distinct elements and false otherwise.

The arguments can be any valid expression as long as they each resolve to an array.

Parameters

$expression1
$expression2

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/setEquals/

$this setIntersection($expression1, $expression2)

Takes two or more arrays and returns an array that contains the elements that appear in every input array.

The arguments can be any valid expression as long as they each resolve to an array.

Parameters

$expression1
$expression2

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/setIntersection/

$this setIsSubset(mixed|Expr $expression1, mixed|Expr $expression2)

Takes two arrays and returns true when the first array is a subset of the second, including when the first array equals the second array, and false otherwise.

The arguments can be any valid expression as long as they each resolve to an array.

Parameters

mixed|Expr $expression1
mixed|Expr $expression2

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/setIsSubset/

$this setUnion($expression1, $expression2)

Takes two or more arrays and returns an array containing the elements that appear in any input array.

The arguments can be any valid expression as long as they each resolve to an array.

Parameters

$expression1
$expression2

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/setUnion/

$this size(mixed|Expr $expression)

Counts and returns the total the number of items in an array.

The argument can be any expression as long as it resolves to an array.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/size/

$this slice(mixed|Expr $array, mixed|Expr $n, mixed|Expr|null $position = null)

Returns a subset of an array.

Parameters

mixed|Expr $array
mixed|Expr $n
mixed|Expr|null $position

Return Value

$this

See also

https://docs.mongodb.org/manual/reference/operator/aggregation/slice/

$this split(mixed|Expr $string, mixed|Expr $delimiter)

Divides a string into an array of substrings based on a delimiter.

$split removes the delimiter and returns the resulting substrings as elements of an array. If the delimiter is not found in the string, $split returns the original string as the only element of an array.

Parameters

mixed|Expr $string The string to be split. Can be any valid expression as long as it resolves to a string.
mixed|Expr $delimiter The delimiter to use when splitting the string expression. Can be any valid expression as long as it resolves to a string.

Return Value

$this

See also

https://docs.mongodb.com/manual/reference/operator/aggregation/split/

$this sqrt(mixed|Expr $expression)

Calculates the square root of a positive number and returns the result as a double.

The argument can be any valid expression as long as it resolves to a non-negative number.

Parameters

mixed|Expr $expression

Return Value

$this

See also

https://docs.mongodb.org/manual/reference/operator/aggregation/sqrt/

$this stdDevPop($expression1)

Calculates the population standard deviation of the input values.

The arguments can be any expression as long as it resolves to an array.

Parameters

$expression1

Return Value

$this

See also

https://docs.mongodb.org/manual/reference/operator/aggregation/stdDevPop/

$this stdDevSamp($expression1)

Calculates the sample standard deviation of the input values.

The arguments can be any expression as long as it resolves to an array.

Parameters

$expression1

Return Value

$this

See also

https://docs.mongodb.org/manual/reference/operator/aggregation/stdDevSamp/

$this strcasecmp(mixed|Expr $expression1, mixed|Expr $expression2)

Performs case-insensitive comparison of two strings. Returns 1 if first string is “greater than” the second string.

0 if the two strings are equal. -1 if the first string is “less than” the second string.

The arguments can be any valid expression as long as they resolve to strings.

Parameters

mixed|Expr $expression1
mixed|Expr $expression2

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/strcasecmp/

$this strLenBytes(mixed|Expr $string)

Returns the number of UTF-8 encoded bytes in the specified string.

Parameters

mixed|Expr $string

Return Value

$this

See also

https://docs.mongodb.com/manual/reference/operator/aggregation/strLenBytes/

$this strLenCP(mixed|Expr $string)

Returns the number of UTF-8 code points in the specified string.

Parameters

mixed|Expr $string

Return Value

$this

See also

https://docs.mongodb.com/manual/reference/operator/aggregation/strLenCP/

$this substr(mixed|Expr $string, mixed|Expr $start, mixed|Expr $length)

Returns a substring of a string, starting at a specified index position and including the specified number of characters. The index is zero-based.

The arguments can be any valid expression as long as long as the first argument resolves to a string, and the second and third arguments resolve to integers.

Parameters

mixed|Expr $string
mixed|Expr $start
mixed|Expr $length

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/substr/

$this substrBytes(mixed|Expr $string, mixed|Expr $start, mixed|Expr $count)

Returns the substring of a string.

The substring starts with the character at the specified UTF-8 byte index (zero-based) in the string and continues for the number of bytes specified.

Parameters

mixed|Expr $string The string from which the substring will be extracted. Can be any valid expression as long as it resolves to a string.
mixed|Expr $start Indicates the starting point of the substring. Can be any valid expression as long as it resolves to a non-negative integer or number that can be represented as an integer.
mixed|Expr $count Can be any valid expression as long as it resolves to a non-negative integer or number that can be represented as an integer.

Return Value

$this

See also

https://docs.mongodb.com/manual/reference/operator/aggregation/substrBytes/

$this substrCP(mixed|Expr $string, mixed|Expr $start, mixed|Expr $count)

Returns the substring of a string.

The substring starts with the character at the specified UTF-8 code point (CP) index (zero-based) in the string for the number of code points specified.

Parameters

mixed|Expr $string The string from which the substring will be extracted. Can be any valid expression as long as it resolves to a string.
mixed|Expr $start Indicates the starting point of the substring. Can be any valid expression as long as it resolves to a non-negative integer or number that can be represented as an integer.
mixed|Expr $count Can be any valid expression as long as it resolves to a non-negative integer or number that can be represented as an integer.

Return Value

$this

See also

https://docs.mongodb.com/manual/reference/operator/aggregation/substrBytes/

$this subtract(mixed|Expr $expression1, mixed|Expr $expression2)

Subtracts two numbers to return the difference. The second argument is subtracted from the first argument.

The arguments can be any valid expression as long as they resolve to numbers and/or dates.

Parameters

mixed|Expr $expression1
mixed|Expr $expression2

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/subtract/

$this sum(mixed|Expr $expression)

Calculates and returns the sum of all the numeric values that result from applying a specified expression to each document in a group of documents that share the same group by key. Ignores nun-numeric values.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/sum/

protected $this switchInternal() deprecated

deprecated Method will be renamed to "switch" in next major version

Evaluates a series of case expressions. When it finds an expression which evaluates to true, $switch executes a specified expression and breaks out of the control flow.

To add statements, use the {@link case()}, {@link then()} and {@link default()} methods.

Return Value

$this

protected $this thenInternal(mixed|Expr $expression) deprecated

deprecated Method will be renamed to "then" in next major version

Adds a case statement for the current branch of the $switch operator.

Requires {@link case()} to be called first. The argument can be any valid expression.

Parameters

mixed|Expr $expression

Return Value

$this

$this toLower(mixed|Expr $expression)

Converts a string to lowercase, returning the result.

The argument can be any expression as long as it resolves to a string.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/toLower/

$this toUpper(mixed|Expr $expression)

Converts a string to uppercase, returning the result.

The argument can be any expression as long as it resolves to a string.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/toUpper/

$this trunc(mixed|Expr $number)

Truncates a number to its integer.

The expression can be any valid expression as long as it resolves to a number.

Parameters

mixed|Expr $number

Return Value

$this

See also

https://docs.mongodb.org/manual/reference/operator/aggregation/trunc/

$this type(mixed|Expr $expression)

Returns a string that specifies the BSON type of the argument.

The argument can be any valid expression.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/type/

$this week(mixed|Expr $expression)

Returns the week of the year for a date as a number between 0 and 53.

The argument can be any expression as long as it resolves to a date.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/week/

$this year(mixed|Expr $expression)

Returns the year portion of a date.

The argument can be any expression as long as it resolves to a date.

Parameters

mixed|Expr $expression

Return Value

$this

See also

http://docs.mongodb.org/manual/reference/operator/aggregation/year/

$this zip(mixed|Expr $inputs, bool|null $useLongestLength = null, mixed|Expr|null $defaults = null)

Transposes an array of input arrays so that the first element of the output array would be an array containing, the first element of the first input array, the first element of the second input array, etc.

Parameters

mixed|Expr $inputs An array of expressions that resolve to arrays. The elements of these input arrays combine to form the arrays of the output array.
bool|null $useLongestLength A boolean which specifies whether the length of the longest array determines the number of arrays in the output array.
mixed|Expr|null $defaults An array of default element values to use if the input arrays have different lengths. You must specify useLongestLength: true along with this field, or else $zip will return an error.

Return Value

$this

See also

https://docs.mongodb.com/manual/reference/operator/aggregation/zip/