class Group extends Operator (View source)

Fluent interface for adding a $group stage to an aggregation pipeline.

Properties

protected Builder $builder from Stage
protected Expr $expr

Methods

__construct(Builder $builder)

No description

getExpression()

Assembles the aggregation stage

execute(array $options = [])

Executes the aggregation pipeline

from Stage
bucket()

Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries.

from Stage
bucketAuto()

Categorizes incoming documents into a specific number of groups, called buckets, based on a specified expression.

from Stage
collStats()

Returns statistics regarding a collection or view.

from Stage
count(string $fieldName)

Returns a document that contains a count of the number of documents input to the stage.

from Stage
facet()

Processes multiple aggregation pipelines within a single stage on the same set of input documents.

from Stage
geoNear(float|array|Point $x, float $y = null)

Outputs documents in order of nearest to farthest from a specified point.

from Stage
getPipeline()

Returns the assembled aggregation pipeline

from Stage
graphLookup(string $from)

Performs a recursive search on a collection, with options for restricting the search by recursion depth and query filter.

from Stage
group()

Groups documents by some specified expression and outputs to the next stage a document for each distinct grouping.

from Stage
indexStats()

Returns statistics regarding the use of each index for the collection.

from Stage
limit(int $limit)

Limits the number of documents passed to the next stage in the pipeline.

from Stage
lookup(string $from)

Performs a left outer join to an unsharded collection in the same database to filter in documents from the “joined” collection for processing.

from Stage
match()

Filters the documents to pass only the documents that match the specified condition(s) to the next pipeline stage.

from Stage
out(string $collection)

Takes the documents returned by the aggregation pipeline and writes them to a specified collection. This must be the last stage in the pipeline.

from Stage
project()

Passes along the documents with only the specified fields to the next stage in the pipeline. The specified fields can be existing fields from the input documents or newly computed fields.

from Stage
redact()

Restricts the contents of the documents based on information stored in the documents themselves.

from Stage
replaceRoot(string|array|null $expression = null)

Promotes a specified document to the top level and replaces all other fields.

from Stage
sample(int $size)

Randomly selects the specified number of documents from its input.

from Stage
skip(int $skip)

Skips over the specified number of documents that pass into the stage and passes the remaining documents to the next stage in the pipeline.

from Stage
sortByCount(string $expression)

Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group.

from Stage
sort(array|string $fieldName, int|string $order = null)

Sorts all input documents and returns them to the pipeline in sorted order.

from Stage
unwind(string $fieldName)

Deconstructs an array field from the input documents to output a document for each element. Each output document is the input document with the value of the array field replaced by the element.

from Stage
__call(string $method, array $args)

No description

from Operator
abs(mixed|Expr $number)

Returns the absolute value of a number.

from Operator
add(mixed|Expr $expression1, mixed|Expr $expression2, mixed|Expr ...$expressions)

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.

from Operator
addAnd(array|Expr $expression, array|Expr ...$expressions)

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

from Operator
addOr(array|Expr $expression, array|Expr ...$expressions)

Add one or more $or clauses to the current expression.

from Operator
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.

from Operator
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.

from Operator
arrayElemAt(mixed|Expr $array, mixed|Expr $index)

Returns the element at the specified array index.

from Operator
ceil(mixed|Expr $number)

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

from Operator
cmp(mixed|Expr $expression1, mixed|Expr $expression2)

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

from Operator
concat(mixed|Expr $expression1, mixed|Expr $expression2, mixed|Expr ...$expressions)

Concatenates strings and returns the concatenated string.

from Operator
concatArrays(mixed|Expr $array1, mixed|Expr $array2, mixed|Expr ...$arrays)

Concatenates arrays to return the concatenated array.

from Operator
cond(mixed|Expr $if, mixed|Expr $then, mixed|Expr $else)

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

from Operator
dateToString(string $format, mixed|Expr $expression)

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

from Operator
dayOfMonth(mixed|Expr $expression)

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

from Operator
dayOfWeek(mixed|Expr $expression)

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

from Operator
dayOfYear(mixed|Expr $expression)

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

from Operator
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.

from Operator
eq(mixed|Expr $expression1, mixed|Expr $expression2)

Compares two values and returns whether they are equivalent.

from Operator
exp(mixed|Expr $exponent)

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

from Operator
expression(mixed|Expr $value)

Used to use an expression as field value. Can be any expression

field(string $fieldName)

Set the current field for building the expression.

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

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

from Operator
floor(mixed|Expr $number)

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

from Operator
gt(mixed|Expr $expression1, mixed|Expr $expression2)

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

from Operator
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.

from Operator
hour(mixed|Expr $expression)

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

from Operator
in(mixed|Expr $expression, mixed|Expr $arrayExpression)

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

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

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

from Operator
indexOfBytes(mixed|Expr $stringExpression, mixed|Expr $substringExpression, string|int|null $start = null, string|int|null $end = null)

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

from Operator
indexOfCP(mixed|Expr $stringExpression, mixed|Expr $substringExpression, string|int|null $start = null, string|int|null $end = null)

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

from Operator
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.

from Operator
isArray(mixed|Expr $expression)

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

from Operator
isoDayOfWeek(mixed|Expr $expression)

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

from Operator
isoWeek(mixed|Expr $expression)

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

from Operator
isoWeekYear(mixed|Expr $expression)

Returns the year number in ISO 8601 format.

from Operator
let(mixed|Expr $vars, mixed|Expr $in)

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

from Operator
literal(mixed|Expr $value)

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

from Operator
ln(mixed|Expr $number)

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

from Operator
log(mixed|Expr $number, mixed|Expr $base)

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

from Operator
log10(mixed|Expr $number)

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

from Operator
lt(mixed|Expr $expression1, mixed|Expr $expression2)

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

from Operator
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.

from Operator
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.

from Operator
meta(mixed|Expr $metaDataKeyword)

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

from Operator
millisecond(mixed|Expr $expression)

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

from Operator
minute(mixed|Expr $expression)

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

from Operator
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.

from Operator
month(mixed|Expr $expression)

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

from Operator
multiply(mixed|Expr $expression1, mixed|Expr $expression2, mixed|Expr ...$expressions)

Multiplies numbers together and returns the result.

from Operator
ne(mixed|Expr $expression1, mixed|Expr $expression2)

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

from Operator
not(mixed|Expr $expression)

Evaluates a boolean and returns the opposite boolean value.

from Operator
pow(mixed|Expr $number, mixed|Expr $exponent)

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

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

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

from Operator
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.

from Operator
reverseArray(mixed|Expr $expression)

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

from Operator
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.

from Operator
setDifference(mixed|Expr $expression1, mixed|Expr $expression2)

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

from Operator
setEquals($expression1, $expression2, ...$expressions)

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

from Operator
setIntersection(mixed|Expr $expression1, mixed|Expr $expression2, mixed|Expr ...$expressions)

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

from Operator
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.

from Operator
setUnion(mixed|Expr $expression1, mixed|Expr $expression2, mixed|Expr ...$expressions)

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

from Operator
size(mixed|Expr $expression)

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

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

Returns a subset of an array.

from Operator
split(mixed|Expr $string, mixed|Expr $delimiter)

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

from Operator
sqrt(mixed|Expr $expression)

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

from Operator
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.

from Operator
strLenBytes(mixed|Expr $string)

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

from Operator
strLenCP(mixed|Expr $string)

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

from Operator
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.

from Operator
substrBytes(mixed|Expr $string, mixed|Expr $start, mixed|Expr $count)

Returns the substring of a string.

from Operator
substrCP(mixed|Expr $string, mixed|Expr $start, mixed|Expr $count)

Returns the substring of a string.

from Operator
subtract(mixed|Expr $expression1, mixed|Expr $expression2)

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

from Operator
toLower(mixed|Expr $expression)

Converts a string to lowercase, returning the result.

from Operator
toUpper(mixed|Expr $expression)

Converts a string to uppercase, returning the result.

from Operator
trunc(mixed|Expr $number)

Truncates a number to its integer.

from Operator
type(mixed|Expr $expression)

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

from Operator
week(mixed|Expr $expression)

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

from Operator
year(mixed|Expr $expression)

Returns the year portion of a date.

from Operator
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.

from Operator
$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.

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.

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.

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.

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.

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.

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.

stdDevPop(mixed|Expr $expression)

Calculates the population standard deviation of the input values.

stdDevSamp(mixed|Expr $expression)

Calculates the sample standard deviation of the input values.

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.

Details

__construct(Builder $builder)

Parameters

Builder $builder

getExpression()

Assembles the aggregation stage

execute(array $options = [])

Executes the aggregation pipeline

Parameters

array $options

bucket()

Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries.

Each bucket is represented as a document in the output. The document for each bucket contains an _id field, whose value specifies the inclusive lower bound of the bucket and a count field that contains the number of documents in the bucket. The count field is included by default when the output is not specified.

bucketAuto()

Categorizes incoming documents into a specific number of groups, called buckets, based on a specified expression.

Bucket boundaries are automatically determined in an attempt to evenly distribute the documents into the specified number of buckets. Each bucket is represented as a document in the output. The document for each bucket contains an _id field, whose value specifies the inclusive lower bound and the exclusive upper bound for the bucket, and a count field that contains the number of documents in the bucket. The count field is included by default when the output is not specified.

collStats()

Returns statistics regarding a collection or view.

$collStats must be the first stage in an aggregation pipeline, or else the pipeline returns an error.

count(string $fieldName)

Returns a document that contains a count of the number of documents input to the stage.

facet()

Processes multiple aggregation pipelines within a single stage on the same set of input documents.

Each sub-pipeline has its own field in the output document where its results are stored as an array of documents.

geoNear(float|array|Point $x, float $y = null)

Outputs documents in order of nearest to farthest from a specified point.

You can only use this as the first stage of a pipeline.

Parameters

float|array|Point $x
float $y

See also

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

getPipeline()

Returns the assembled aggregation pipeline

graphLookup(string $from)

Performs a recursive search on a collection, with options for restricting the search by recursion depth and query filter.

Parameters

string $from Target collection for the $graphLookup operation to search, recursively matching the connectFromField to the connectToField.

See also

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

group()

Groups documents by some specified expression and outputs to the next stage a document for each distinct grouping.

indexStats()

Returns statistics regarding the use of each index for the collection.

Limit limit(int $limit)

Limits the number of documents passed to the next stage in the pipeline.

lookup(string $from)

Performs a left outer join to an unsharded collection in the same database to filter in documents from the “joined” collection for processing.

match()

Filters the documents to pass only the documents that match the specified condition(s) to the next pipeline stage.

out(string $collection)

Takes the documents returned by the aggregation pipeline and writes them to a specified collection. This must be the last stage in the pipeline.

project()

Passes along the documents with only the specified fields to the next stage in the pipeline. The specified fields can be existing fields from the input documents or newly computed fields.

redact()

Restricts the contents of the documents based on information stored in the documents themselves.

replaceRoot(string|array|null $expression = null)

Promotes a specified document to the top level and replaces all other fields.

The operation replaces all existing fields in the input document, including the _id field. You can promote an existing embedded document to the top level, or create a new document for promotion.

Parameters

string|array|null $expression Optional. A replacement expression that resolves to a document.

sample(int $size)

Randomly selects the specified number of documents from its input.

skip(int $skip)

Skips over the specified number of documents that pass into the stage and passes the remaining documents to the next stage in the pipeline.

sortByCount(string $expression)

Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group.

sort(array|string $fieldName, int|string $order = null)

Sorts all input documents and returns them to the pipeline in sorted order.

If sorting by multiple fields, the first argument should be an array of field name (key) and order (value) pairs.

Parameters

array|string $fieldName Field name or array of field/order pairs
int|string $order Field order (if one field is specified)

See also

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

unwind(string $fieldName)

Deconstructs an array field from the input documents to output a document for each element. Each output document is the input document with the value of the array field replaced by the element.

__call(string $method, array $args)

Parameters

string $method
array $args

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.

add(mixed|Expr $expression1, mixed|Expr $expression2, mixed|Expr ...$expressions)

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

mixed|Expr $expression1
mixed|Expr $expression2
mixed|Expr ...$expressions Additional expressions

See also

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

addAnd(array|Expr $expression, array|Expr ...$expressions)

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

Parameters

array|Expr $expression
array|Expr ...$expressions

See also

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

addOr(array|Expr $expression, array|Expr ...$expressions)

Add one or more $or clauses to the current expression.

Parameters

array|Expr $expression
array|Expr ...$expressions

See also

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

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

See also

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

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

See also

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

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

See also

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

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

See also

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

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

See also

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

concat(mixed|Expr $expression1, mixed|Expr $expression2, mixed|Expr ...$expressions)

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

mixed|Expr $expression1
mixed|Expr $expression2
mixed|Expr ...$expressions Additional expressions

See also

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

concatArrays(mixed|Expr $array1, mixed|Expr $array2, mixed|Expr ...$arrays)

Concatenates arrays to return the concatenated array.

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

Parameters

mixed|Expr $array1
mixed|Expr $array2
mixed|Expr ...$arrays Additional expressions

See also

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

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

See also

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

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

See also

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

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

See also

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

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

See also

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

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

See also

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

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

See also

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

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

Compares two values and returns whether they are equivalent.

Parameters

mixed|Expr $expression1
mixed|Expr $expression2

See also

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

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

See also

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

expression(mixed|Expr $value)

Used to use an expression as field value. Can be any expression

field(string $fieldName)

Set the current field for building the expression.

Parameters

string $fieldName

See also

Expr::field

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

See also

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

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

See also

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

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

See also

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

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

See also

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

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

See also

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

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

See also

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

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

Searches an array for an occurrence of a specified value and returns the array index (zero-based) of the first occurrence. 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.

See also

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

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

Searches a string for an occurrence of a substring and returns the UTF-8 byte index (zero-based) of the first occurrence. 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.
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.
string|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.

See also

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

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

Searches a string for an occurrence of a substring and returns the UTF-8 code point index (zero-based) of the first occurrence. 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.
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.
string|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.

See also

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

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

See also

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

isArray(mixed|Expr $expression)

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

The can be any valid expression.

Parameters

mixed|Expr $expression

See also

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

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.

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.

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.

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.

See also

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

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

See also

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

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.

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

See also

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

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. The expression can be any valid expression as long as it resolves to a positive number greater than 1.

Parameters

mixed|Expr $number

See also

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

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

See also

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

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

See also

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

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.

See also

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

meta(mixed|Expr $metaDataKeyword)

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

Parameters

mixed|Expr $metaDataKeyword

See also

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

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

See also

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

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

See also

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

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

See also

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

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

See also

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

multiply(mixed|Expr $expression1, mixed|Expr $expression2, mixed|Expr ...$expressions)

Multiplies numbers together and returns the result.

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

Parameters

mixed|Expr $expression1
mixed|Expr $expression2
mixed|Expr ...$expressions Additional expressions

See also

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

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

See also

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

not(mixed|Expr $expression)

Evaluates a boolean and returns the opposite boolean value.

Parameters

mixed|Expr $expression

See also

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

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

See also

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

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.

See also

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

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.

See also

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

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

See also

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

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

See also

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

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

See also

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

setEquals($expression1, $expression2, ...$expressions)

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
...$expressions

See also

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

setIntersection(mixed|Expr $expression1, mixed|Expr $expression2, mixed|Expr ...$expressions)

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

mixed|Expr $expression1
mixed|Expr $expression2
mixed|Expr ...$expressions Additional sets

See also

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

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

See also

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

setUnion(mixed|Expr $expression1, mixed|Expr $expression2, mixed|Expr ...$expressions)

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

mixed|Expr $expression1
mixed|Expr $expression2
mixed|Expr ...$expressions Additional sets

See also

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

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

See also

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

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

See also

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

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.

See also

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

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

See also

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

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

See also

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

strLenBytes(mixed|Expr $string)

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

strLenCP(mixed|Expr $string)

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

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

See also

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

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.

See also

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

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.

See also

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

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

See also

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

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

See also

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

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

See also

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

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

See also

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

type(mixed|Expr $expression)

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

The argument can be any valid expression.

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

See also

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

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

See also

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

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.

See also

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

$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/
Expr::addToSet

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

See also

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

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

See also

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

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

See also

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

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

See also

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

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

See also

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

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

See also

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

stdDevPop(mixed|Expr $expression)

Calculates the population standard deviation of the input values.

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

Parameters

mixed|Expr $expression

See also

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

stdDevSamp(mixed|Expr $expression)

Calculates the sample standard deviation of the input values.

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

Parameters

mixed|Expr $expression

See also

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

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

See also

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