AggregateCommand
Database aggregation operator, accessed via db.command.aggregate
AggregateCommand.abs(value: number | Expression\<number>)
Description: Aggregation operator. Returns the absolute value of a number.
AggregateCommand.add(value: Expression[])
Description: Aggregation operator. Adds numbers together or adds numbers to a date. If one of the values in the array is a date, the other values are treated as milliseconds added to that date.
AggregateCommand.addToSet(value: Expression)
Description: Aggregation operator. Adds a value to an array. If the value already exists in the array, no operation is performed. It can only be used in the group stage.
AggregateCommand.allElementsTrue(value: Expression[])
Description: Aggregation operator. Takes an array or an expression that resolves to an array. Returns true if all elements in the array are truthy, otherwise returns false. An empty array always returns true.
AggregateCommand.and(value: Expression[])
Description: Aggregation operator. Given multiple expressions, and returns true only if all expressions evaluate to true; otherwise, it returns false.
AggregateCommand.anyElementTrue(value: Expression[])
Description: Aggregation operator. Takes an array or an expression that resolves to an array. Returns true if any element in the array is truthy, otherwise returns false. An empty array always returns false.
AggregateCommand.arrayElemAt(value: Expression[])
Description: Aggregation operator. Returns the element at the specified array index.
AggregateCommand.arrayToObject(value: any)
Description: Aggregation operator. Converts an array to an object.
AggregateCommand.avg(value: Expression\<number>)
Description: Aggregation operator. Returns the average value of the specified field in a collection.
AggregateCommand.ceil(value: Expression\<number>)
Description: Aggregation operator. Rounds a number up to the nearest integer, returning the smallest integer greater than or equal to the given number.
AggregateCommand.cmp(value: Expression[])
Description: Aggregation operator. Given two values, returns the comparison result.
AggregateCommand.concat(value: Expression[])
Description: Aggregation operator. Concatenates strings and returns the concatenated string.
AggregateCommand.concatArrays(value: Expression[])
Description: Aggregation operator. Concatenates multiple arrays into a single array.
AggregateCommand.cond(value: any)
Description: Aggregation operator. Evaluates a boolean expression and returns one of the two specified values.
AggregateCommand.dateFromParts(value: any)
Description: Aggregation operator. Given date-related information, constructs and returns a date object.
AggregateCommand.dateFromString(value: any)
Description: Aggregation operator. Converts a date/time string to a date object.
AggregateCommand.dateToString(value: any)
Description: Aggregation operator. Formats a date object into a compliant string according to the specified expression.
AggregateCommand.dayOfMonth(value: Expression\<string>)
Description: Aggregation operator. Returns the day of the month for a date field, which is a number between 1 and 31.
AggregateCommand.dayOfWeek(value: Expression\<string>)
Description: Aggregation operator. Returns the day of the week for a date field, which is an integer ranging from 1 (Sunday) to 7 (Saturday).
AggregateCommand.dayOfYear(value: Expression\<string>)
Description: Aggregation operator. Returns the day of the year for a date field, which is an integer between 1 and 366.
AggregateCommand.divide(value: Expression[])
Description: Aggregation operator. Takes the dividend and divisor, and calculates the quotient.
AggregateCommand.eq(value: Expression[])
Description: Aggregation operator. Compares two values and returns true if they are equal, otherwise returns false.
AggregateCommand.exp(value: Expression\<number>)
Description: Aggregation operator. Raises e (the base of natural logarithms, Euler's number) to the power of n.
AggregateCommand.filter(value: any)
Description: Aggregation operator. Returns a subset of the array that meets the given conditions.
AggregateCommand.first(value: Expression)
Description: Aggregation operator. Returns the value of the specified field from the first document in a set of documents. This operation is meaningful only when the set of documents is sorted by some definition.
AggregateCommand.floor(value: Expression\<number>)
Description: Aggregation operator. Rounds a number down to the nearest integer, returning the largest integer less than or equal to the given number.
AggregateCommand.gt(value: Expression[])
Description: Aggregation operator. Compares two values and returns true if the first is greater than the second, otherwise returns false.
AggregateCommand.gte(value: Expression[])
Description: Aggregation operator. Compares two values and returns true if the first is greater than or equal to the second, otherwise returns false.
AggregateCommand.hour(value: Expression\<string>)
Description: Aggregation operator. Returns the hour for a date field, which is an integer between 0 and 23.
AggregateCommand.ifNull(value: Expression[])
Description: Aggregation operator. Evaluates a given expression and returns a replacement value if the expression results in null, undefined, or does not exist; otherwise returns the original value.
AggregateCommand.in(value: Expression[])
Description: Aggregation operator. Given a value and an array, returns true if the value is in the array, otherwise returns false.
AggregateCommand.indexOfArray(value: Expression[])
Description: Aggregation operator. Finds the index of the first element in an array that equals the given value. If not found, returns -1.
AggregateCommand.indexOfBytes(value: Expression[])
Description: Aggregation operator. Searches for a substring in a target string and returns the byte index (starting from 0) of the first occurrence in UTF-8 encoding. If the substring does not exist, returns -1.
AggregateCommand.indexOfCP(value: Expression[])
Description: Aggregation operator. Searches for a substring in a target string and returns the code point index (starting from 0) of the first occurrence in UTF-8 encoding. If the substring does not exist, returns -1.
AggregateCommand.isArray(value: Expression)
Description: Aggregation operator. Determines whether a given expression is an array and returns a boolean value.
AggregateCommand.isoDayOfWeek(value: Expression\<string>)
Description: Aggregation operator. Returns the ISO 8601 day of the week for a date field, which is an integer ranging from 1 (Monday) to 7 (Sunday).
AggregateCommand.isoWeek(value: Expression\<string>)
Description: Aggregation operator. Returns the ISO 8601 week number (the week of the year) for a date field, which is an integer between 1 and 53.
AggregateCommand.isoWeekYear(value: Expression\<string>)
Description: Aggregation operator. Returns the ISO 8601 day of the year for a date field.
AggregateCommand.last(value: Expression)
Description: Aggregation operator. Returns the value of the specified field from the last document in a set of documents. This operation is meaningful only when the set of documents is sorted by some definition.
AggregateCommand.let(value: any)
Description: Aggregation operator. Defines custom variables and uses them in a specified expression, returning the result of the expression.
AggregateCommand.literal(value: any)
Description: Aggregation operator. Directly returns the literal value without any parsing or processing.
AggregateCommand.ln(value: Expression\<number>)
Description: Aggregation operator. Calculates the natural logarithm of a given number.
AggregateCommand.log(value: Expression[])
Description: Aggregation operator. Calculates the logarithm of a given number with a specified base.
AggregateCommand.log10(value: Expression\<number>)
Description: Aggregation operator. Calculates the base-10 logarithm of a given number.
AggregateCommand.lt(value: Expression[])
Description: Aggregation operator. Compares two values and returns true if the first is less than the second, otherwise returns false.
AggregateCommand.lte(value: Expression[])
Description: Aggregation operator. Compares two values and returns true if the first is less than or equal to the second, otherwise returns false.
AggregateCommand.map(value: any)
Description: Aggregation operator. Similar to the map method on JavaScript Array, transforms each element of a given array according to a specified transformation method to produce a new array.
AggregateCommand.max(value: Expression)
Description: Aggregation operator. Returns the maximum value in a set of numbers.
AggregateCommand.mergeObjects(value: Expression\<document>)
Description: Aggregation operator. Merges multiple documents into a single document.
AggregateCommand.millisecond(value: Expression\<string>)
Description: Aggregation operator. Returns the milliseconds for a date field, which is an integer between 0 and 999.
AggregateCommand.min(value: Expression)
Description: Aggregation operator. Returns the minimum value in a set of numbers.
AggregateCommand.minute(value: Expression\<string>)
Description: Aggregation operator. Returns the minute for a date field, which is an integer between 0 and 59.
AggregateCommand.mod(value: Expression[])
Description: Aggregation operator. Performs a modulo operation and returns the remainder.
AggregateCommand.month(value: Expression\<string>)
Description: Aggregation operator. Returns the month for a date field, which is an integer between 1 and 12.
AggregateCommand.multiply(value: Expression[])
Description: Aggregation operator. Returns the product of the input numbers.
AggregateCommand.neq(value: Expression[])
Description: Aggregation operator. Compares two values and returns true if they are not equal, otherwise returns false.
AggregateCommand.not(value: Expression)
Description: Aggregation operator. Given an expression, if the expression returns true, then not returns false; otherwise, it returns true. Note that the expression cannot be a logical expression (and, or, nor, not).
AggregateCommand.objectToArray(value: Expression\<object>)
Description: Aggregation operator. Converts an object to an array. The method transforms each key-value pair of the object into an element in the output array, with each element in the form { k: \<key>, v: \<value> }.
AggregateCommand.or(value: Expression[])
Description: Aggregation operator. Given multiple expressions, or returns true if any expression evaluates to true; otherwise, it returns false.
AggregateCommand.pow(value: Expression[])
Description: Aggregation operator. Raises a base to the specified exponent.
AggregateCommand.push(value: any)
Description: Aggregation operator. In the group stage, returns an array composed of the expression-specified column and its corresponding values within a group.
AggregateCommand.range(value: Expression[])
Description: Aggregation operator. Returns a sequence of generated numbers. Given a start value, end value, and a non-zero step, range returns a sequence starting from the start value, incrementing by the specified step, and excluding the end value.
AggregateCommand.reduce(value: any)
Description: Aggregation operator. Similar to JavaScript's reduce method, applies an expression to each element of an array and reduces them into a single element.
AggregateCommand.reverseArray(value: Expression\<any[]>)
Description: Aggregation operator. Returns the given array in reverse order.
AggregateCommand.second(value: Expression\<string>)
Description: Aggregation operator. Returns the second for a date field, which is an integer between 0 and 59, and can be 60 in special cases (leap second).
AggregateCommand.setDifference(value: Expression[])
Description: Aggregation operator. Takes two sets as input and outputs elements that exist only in the first set.
AggregateCommand.setEquals(value: Expression[])
Description: Aggregation operator. Takes two sets as input and determines whether they contain identical elements (ignoring order and duplicates).
AggregateCommand.setIntersection(value: Expression[])
Description: Aggregation operator. Takes two sets as input and returns their intersection.
AggregateCommand.setIsSubset(value: Expression[])
Description: Aggregation operator. Takes two sets as input and determines whether the first set is a subset of the second set.
AggregateCommand.setUnion(value: Expression[])
Description: Aggregation operator. Takes two sets as input and returns their union.
AggregateCommand.size(value: Expression\<any[]>)
Description: Aggregation operator. Returns the length of the array.
AggregateCommand.slice(value: Expression[])
Description: Aggregation operator. Similar to JavaScript's slice method. Returns the specified subset of a given array.
AggregateCommand.split(value: Expression[])
Description: Aggregation operator. Splits an array by a separator, removes the separator, and returns an array of substrings. If the string cannot be split by the separator, returns the original string as the single element of the array.
AggregateCommand.sqrt(value: Expression[])
Description: Aggregation operator. Returns the square root.
AggregateCommand.stdDevPop(value: Expression)
Description: Aggregation operator. Returns the standard deviation of the values corresponding to a set of fields.
AggregateCommand.stdDevSamp(value: Expression)
Description: Aggregation operator. Calculates the sample standard deviation of the input values. If the input values represent the entire population of data, or do not generalize to a larger dataset, use db.command.aggregate.stdDevPop instead.
AggregateCommand.strLenBytes(value: Expression)
Description: Aggregation operator. Calculates and returns the number of bytes in the specified string under utf-8 encoding.
AggregateCommand.strLenCP(value: Expression)
Description: Aggregation operator. Calculates and returns the number of UTF-8 code points in the specified string.
AggregateCommand.strcasecmp(value: Expression[])
Description: Aggregation operator. Compares two strings in a case-insensitive manner and returns the comparison result.
AggregateCommand.substr(value: Expression[])
Description: Aggregation operator. Returns a substring of specified length starting from a specified position in the string. It is an alias for db.command.aggregate.substrBytes, and the latter is recommended.
AggregateCommand.substrBytes(value: Expression[])
Description: Aggregation operator. Returns a substring of specified length starting from a specified position in the string. The substring begins at the character corresponding to the specified UTF-8 byte index and extends for the specified number of bytes.
AggregateCommand.substrCP(value: Expression[])
Description: Aggregation operator. Returns a substring of specified length starting from a specified position in the string. The substring begins at the character corresponding to the specified UTF-8 byte index and extends for the specified number of bytes.
AggregateCommand.subtract(value: Expression[])
Description: Aggregation operator. Subtracts two numbers and returns the difference, subtracts two dates and returns the difference in milliseconds, or subtracts a number from a date and returns the resulting date.
AggregateCommand.sum(value: Expression)
Description: Aggregation operator. Calculates and returns the sum of all numeric values in a set of fields.
AggregateCommand.switch(value: any)
Description: Aggregation operator. Calculates and returns a value based on the given switch-case-default.
AggregateCommand.toLower(value: any)
Description: Aggregation operator. Converts a string to lowercase and returns it.
AggregateCommand.toUpper(value: any)
Description: Aggregation operator. Converts a string to uppercase and returns it.
AggregateCommand.trunc(value: Expression\<number>)
Description: Aggregation operator. Truncates a number to an integer.
AggregateCommand.week(value: Expression\<string>)
Description: Aggregation operator. Returns the week number (the week of the year) for a date field, which is an integer between 0 and 53.
AggregateCommand.year(value: Expression\<string>)
Description: Aggregation operator. Returns the year for a date field.
AggregateCommand.zip(value: any)
Description: Aggregation operator. Assembles elements at the same index position from sub-arrays of a two-dimensional array into new arrays, forming a new two-dimensional array. For example, it can convert [ [ 1, 2, 3 ], [ "a", "b", "c" ] ] into [ [ 1, "a" ], [ 2, "b" ], [ 3, "c" ] ].