Aggregation Pipeline Operators聚合管道运算符
On this page本页内容
Expression Operators表达式运算符Arithmetic Expression Operators算术表达式运算符Array Expression Operators数组表达式运算符Bitwise Operators位运算符Boolean Expression Operators布尔表达式运算符Comparison Expression Operators比较表达式运算符Conditional Expression Operators条件表达式运算符Custom Aggregation Expression Operators自定义聚合表达式运算符Data Size Operators数据大小运算符Date Expression Operators日期表达式运算符Literal Expression Operator文字表达式运算符Miscellaneous Operators混杂运算符Object Expression Operators对象表达式运算符Set Expression Operators设置表达式运算符String Expression Operators字符串表达式运算符Text Expression Operator文本表达式运算符Timestamp Expression Operators时间戳表达式运算符Trigonometry Expression Operators三角表达式运算符Type Expression Operators类型表达式运算符Accumulators (累加器($group, $bucket, $bucketAuto, $setWindowFields
)$group
、$bucket
、$bucketAuto
、$setWindowFields
)Accumulators (in Other Stages)累加器(其他阶段)Variable Expression Operators变量表达式运算符Window Operators窗口运算符Alphabetical Listing of Expression Operators表达式运算符的字母列表
For details on a specific operator, including syntax and examples, click on the link to the operator's reference page.有关特定运算符的详细信息,包括语法和示例,请单击该运算符参考页的链接。
Expression Operators表达式运算符
These expression operators are available to construct expressions for use in the aggregation pipeline stages.这些表达式运算符可用于构造用于聚合管道阶段的表达式。
Operator expressions are similar to functions that take arguments. 运算符表达式类似于接受参数的函数。In general, these expressions take an array of arguments and have the following form:通常,这些表达式采用参数数组,并具有以下形式:
{ <operator>: [ <argument1>, <argument2> ... ] }
If operator accepts a single argument, you can omit the outer array designating the argument list:如果运算符接受单个参数,则可以省略指定参数列表的外部数组:
{ <operator>: <argument> }
To avoid parsing ambiguity if the argument is a literal array, you must wrap the literal array in a 如果参数是文字数组,为了避免解析歧义,必须将文字数组包装在$literal
expression or keep the outer array that designates the argument list.$literal
表达式中,或者保留指定参数列表的外部数组。
Arithmetic Expression Operators算术表达式运算符
Arithmetic expressions perform mathematic operations on numbers. 算术表达式对数字进行数学运算。Some arithmetic expressions can also support date arithmetic.一些算术表达式也可以支持日期算术。
$abs | |
$add | |
$ceil | |
$divide | |
$exp | |
$floor | |
$ln | |
$log | |
$log10 | |
$mod | |
$multiply | |
$pow | |
$round | |
$sqrt | |
$subtract | |
$trunc |
Array Expression Operators数组表达式运算符
$arrayElemAt | |
$arrayToObject | |
$concatArrays | |
$filter | |
$firstN | $firstN accumulator.$firstN 累加器不同。 |
$in | |
$indexOfArray | |
$isArray | |
$lastN | $lastN accumulator.$lastN 累加器不同。 |
$map | |
$maxN | n largest values in an array. n 个值。$maxN accumulator.$maxN 累加器不同。 |
$minN | n smallest values in an array. n 个最小值。$minN accumulator.$minN 累加器不同。 |
$objectToArray | |
$range | |
$reduce | |
$reverseArray | |
$size | |
$slice | |
$sortArray | |
$zip |
Bitwise Operators按位运算符
$bitAnd | and operation on an array of int or long values. int 值或long 值数组执行按位and 运算的结果。 |
$bitNot | not operation on a single argument or an array that contains a single int or long value. int 或long 值的数组执行逐位not 运算的结果。 |
$bitOr | or operation on an array of int or long values. int 或long 值数组执行按位or 运算的结果。 |
$bitXor | xor (exclusive or) operation on an array of int and long values. int 和long 值数组执行逐位xor (异或)运算的结果。 |
Boolean Expression Operators布尔表达式运算符
Boolean expressions evaluate their argument expressions as booleans and return a boolean as the result.布尔表达式将其参数表达式计算为布尔值,并返回布尔值作为结果。
In addition to the 除了false
boolean value, Boolean expression evaluates as false
the following: null
, 0
, and undefined
values. false
布尔值之外,布尔表达式还将以下值计算为false
:null
、0
和undefined
义值。The Boolean expression evaluates all other values as 布尔表达式将所有其他值计算为true
, including non-zero numeric values and arrays.true
,包括非零数值和数组。
$and | true only when all its expressions evaluate to true . true 时才返回true 。 |
$not | |
$or | true when any of its expressions evaluates to true . true 时,返回true 。 |
Comparison Expression Operators比较表达式运算符
Comparison expressions return a boolean except for 比较表达式返回一个布尔值,但$cmp
which returns a number.$cmp
返回一个数字。
The comparison expressions take two argument expressions and compare both value and type, using the specified BSON comparison order for values of different types.比较表达式采用两个参数表达式,并对不同类型的值使用指定的BSON比较顺序来比较值和类型。
$cmp | 0 if the two values are equivalent, 1 if the first value is greater than the second, and -1 if the first value is less than the second. |
$eq | true if the values are equivalent.true 。 |
$gt | true if the first value is greater than the second.true 。 |
$gte | true if the first value is greater than or equal to the second.true 。 |
$lt | true if the first value is less than the second.true 。 |
$lte | true if the first value is less than or equal to the second.true 。 |
$ne | true if the values are not equivalent.true 。 |
Conditional Expression Operators条件表达式运算符
$cond | |
$ifNull | null 结果,如果第一个表达式导致null 结果,则返回第二个表达式的结果。Null 结果包含未定义值或缺少字段的实例。null 。 |
$switch | true , $switch executes a specified expression and breaks out of the control flow.true 的表达式时,$switch 执行指定的表达式并脱离控制流。 |
Custom Aggregation Expression Operators自定义聚合表达式运算符
$accumulator | |
$function |
Data Size Operators数据大小运算符
The following operators return the size of a data element:以下运算符返回数据元素的大小:
$binarySize | |
$bsonSize | Object ) when encoded as BSON. |
Date Expression Operators日期表达式运算符
The following operators returns date objects or components of a date object:以下运算符返回日期对象或日期对象的组件:
$dateAdd | |
$dateDiff | |
$dateFromParts | |
$dateFromString | |
$dateSubtract | |
$dateToParts | |
$dateToString | |
$dateTrunc | |
$dayOfMonth | |
$dayOfWeek | |
$dayOfYear | |
$hour | |
$isoDayOfWeek | 1 (for Monday) to 7 (for Sunday).1 (周一)到7 (周日)。 |
$isoWeek | 1 to 53 . 1 到53 。1 with the week (Monday through Sunday) that contains the year's first Thursday.1 开始,包含一年中第一个星期四的一周(星期一到星期日)。 |
$isoWeekYear | |
$millisecond | |
$minute | |
$month | |
$second | |
$toDate | |
$week | |
$year |
The following arithmetic operators can take date operands:以下算术运算符可以接受日期操作数:
$add | |
$subtract |
Literal Expression Operator文字表达式运算符
$literal | $literal expression to a string that starts with a dollar sign ($ ) to avoid parsing as a field path.$ )开头的字符串使用$literal 表达式,以避免将其解析为字段路径。 |
Miscellaneous Operators杂项运算符
$getField | $getField to retrieve the value of fields with names that contain periods (. ) or start with dollar signs ($ ). $getField 来检索名称包含句点(. )或以美元符号($ )开头的字段的值。 |
$rand | |
$sampleRate |
Object Expression Operators对象表达式运算符
$mergeObjects | |
$objectToArray | |
$setField | $setField to add, update, or remove fields with names that contain periods (. ) or start with dollar signs ($ ). $setField 添加、更新或删除名称包含句点(. )或以美元符号($ )开头的字段。 |
Set Expression Operators设置表达式运算符
Set expressions performs set operation on arrays, treating arrays as sets. 集合表达式对数组执行集合运算,将数组视为集合。Set expressions ignores the duplicate entries in each input array and the order of the elements.Set表达式会忽略每个输入数组中的重复项和元素的顺序。
If the set operation returns a set, the operation filters out duplicates in the result to output an array that contains only unique entries. 如果set操作返回一个集合,则该操作会筛选出结果中的重复项,以输出仅包含唯一项的数组。The order of the elements in the output array is unspecified.输出数组中元素的顺序未指定。
If a set contains a nested array element, the set expression does not descend into the nested array but evaluates the array at top-level.如果集合包含嵌套数组元素,则集合表达式不会下降到嵌套数组中,而是在顶级计算数组。
$allElementsTrue | true if no element of a set evaluates to false , otherwise, returns false . false ,则返回true ,否则返回false 。 |
$anyElementTrue | true if any elements of a set evaluate to true ; otherwise, returns false . true ,则返回true ;否则,返回false 。 |
$setDifference | |
$setEquals | true if the input sets have the same distinct elements. true 。 |
$setIntersection | |
$setIsSubset | true if all elements of the first set appear in the second set, including when the first set equals the second set; i.e. not a strict subsettrue ;即不是严格的子集 |
$setUnion |
String Expression Operators字符串表达式运算符
String expressions, with the exception of 字符串表达式($concat
, only have a well-defined behavior for strings of ASCII characters.$concat
除外)只对ASCII字符字符串具有定义良好的行为。
$concat
behavior is well-defined regardless of the characters used.无论使用什么字符,行为都是定义良好的。
$concat | |
$dateFromString | |
$dateToString | |
$indexOfBytes | -1 .-1 。 |
$indexOfCP | -1 -1 |
$ltrim | |
$regexFind | |
$regexFindAll | |
$regexMatch | |
$replaceOne | |
$replaceAll | |
$rtrim | |
$split | |
$strLenBytes | |
$strLenCP | |
$strcasecmp | 0 if two strings are equivalent, 1 if the first string is greater than the second, and -1 if the first string is less than the second.0 ;如果第一个字符串大于第二个字符串,则返回1 ;如果第一条字符串小于第二个,则返回-1 。 |
$substr | $substrBytes or $substrCP .$substrBytes 或$substrCP 。 |
$substrBytes | |
$substrCP | |
$toLower | |
$toString | |
$trim | |
$toUpper |
Text Expression Operator文本表达式运算符
$meta |
Timestamp Expression Operators时间戳表达式运算符
Timestamp expression operators return values from a timestamp.时间戳表达式运算符从时间戳返回值。
$tsIncrement | long . long 形式返回时间戳中的递增序号。 |
$tsSecond | long . long 形式返回时间戳中的秒。 |
Trigonometry Expression Operators三角表达式运算符
Trigonometry expressions perform trigonometric operations on numbers. 三角表达式对数字执行三角运算。Values that represent angles are always input or output in radians. 表示角度的值始终以弧度为单位输入或输出。Use 使用$degreesToRadians
and $radiansToDegrees
to convert between degree and radian measurements.$degreesToRadians
和$radiansToDegrees
在度数和弧度测量之间转换。
$sin | |
$cos | |
$tan | |
$asin | |
$acos | |
$atan | |
$atan2 | y / x in radians, where y and x are the first and second values passed to the expression respectively.y/x 的反正切(反正切),其中y 和x 分别是传递给表达式的第一个值和第二个值。 |
$asinh | |
$acosh | |
$atanh | |
$sinh | |
$cosh | |
$tanh | |
$degreesToRadians | |
$radiansToDegrees |
Type Expression Operators类型表达式运算符
$convert | |
$isNumber | true if the specified expression resolves to an integer , decimal , double , or long .integer 、decimal 、double 或long ,则返回布尔值true 。false if the expression resolves to any other BSON type, null , or a missing field. null 或缺少字段,则返回布尔值false 。 |
$toBool | boolean 。 |
$toDate | Date 。 |
$toDecimal | Decimal128 。 |
$toDouble | double 。 |
$toInt | integer 。 |
$toLong | long 。 |
$toObjectId | ObjectId 。 |
$toString | |
$type |
Accumulators累加器 ($group, $bucket, $bucketAuto, $setWindowFields
)
Aggregation accumulator operators:聚合累加器运算符:
Maintain their state as documents progress through the aggregation pipeline.在文档通过聚合管道时维护它们的状态。Return totals, maxima, minima, and other values.返回总计、最大值、最小值和其他值。Can be used in these aggregation pipeline stages:可用于以下聚合管道阶段:$bucket
$bucketAuto
$group
$setWindowFields
starting in MongoDB 5.0 (except when you are using the从MongoDB 5.0开始(除非使用$accumulator
or$mergeObjects
operators, which cannot be used with$setWindowFields
)$accumulator
或$mergeObjects
运算符,它们不能与$setWindowFields
一起使用)
Changed in version 5.05.0版更改.
$accumulator | |
$addToSet | $setWindowFields stage. $setWindowFields 阶段中可用。 |
$avg | $setWindowFields stage. $setWindowFields 阶段中可用。 |
$bottom | $group and $setWindowFields stages. $group 和$setWindowFields 阶段中可用。 |
$bottomN | n fields within a group, according to the specified sort order. n 个字段的聚合。$group and $setWindowFields stages. $group 和$setWindowFields 阶段中可用。 |
$count | $count pipeline stage. $count 管道阶段不同。$group and $setWindowFields stages. $group 和$setWindowFields 阶段中可用。 |
$first | $setWindowFields stage. $setWindowFields 阶段中可用。 |
$firstN | n elements within a group. n 个元素的聚合。$firstN array operator. $firstN 数组运算符不同。$group , expression and $setWindowFields stages. $group 、表达式和$setWindowFields 阶段中可用。 |
$last | $setWindowFields stage. $setWindowFields 阶段中可用。 |
$lastN | n elements within a group. $lastN array operator. $lastN 数组运算符不同。$group , expression and $setWindowFields stages. $group 、表达式和$setWindowFields 阶段中可用。 |
$max | $setWindowFields stage. $setWindowFields 阶段中可用。 |
$maxN | n maximum valued elements in a group. $maxN array operator. $maxN 数组运算符不同。$group , $setWindowFields and as an expression. $group 、$setWindowFields 中可用,并用作表达式。 |
$median | |
$mergeObjects | |
$min | $setWindowFields stage. $setWindowFields 阶段中可用。 |
$percentile | |
$push | $setWindowFields stage. $setWindowFields 阶段中可用。 |
$stdDevPop | $setWindowFields stage. $setWindowFields 阶段中可用。 |
$stdDevSamp | $setWindowFields stage. $setWindowFields 阶段中可用。 |
$sum | $setWindowFields stage. $setWindowFields 阶段中可用。 |
$top | $group and $setWindowFields stages. $group 和$setWindowFields 阶段中可用。 |
$topN | n fields within a group, according to the specified sort order. $group and $setWindowFields stages. $group 和$setWindowFields 阶段中可用。 |
Accumulators (in Other Stages)累加器(其他阶段)
Some operators that are available as accumulators for the 一些可作为$group
stage are also available for use in other stages but not as accumulators. $group
阶段的累加器的运算符也可用于其他阶段,但不能用作累加器。When used in these other stages, these operators do not maintain their state and can take as input either a single argument or multiple arguments. 当在这些其他阶段中使用时,这些运算符不维护其状态,可以将单个参数或多个参数作为输入。For details, refer to the specific operator page.有关详细信息,请参阅特定的运算符页面。
Changed in version 5.05.0版更改.
The following accumulator operators are also available in the 以下累加器运算符也可用于$project
, $addFields
, $set
, and, starting in MongoDB 5.0, the $setWindowFields
stages.$project
、$addFields
、$set
,以及从MongoDB 5.0开始的$setWindowFields
阶段。
$avg | |
$first | |
$last | |
$max | |
$median | |
$min | |
$percentile | |
$stdDevPop | |
$stdDevSamp | |
$sum |
Variable Expression Operators变量表达式运算符
$let |
Window Operators窗口运算符
New in version 5.0.5.0版新增。
Window operators return values from a defined span of documents from a collection, known as a window. 窗口运算符从集合(称为窗口)中定义的文档范围中返回值。A window is defined in the 窗口是在$setWindowFields
stage, available starting in MongoDB 5.0.$setWindowFields
阶段定义的,从MongoDB 5.0开始就可以使用。
The following window operators are available in the 以下窗口运算符在$setWindowFields
stage.$setWindowFields
阶段中可用。
$addToSet | $setWindowFields stage. $setWindowFields 阶段中可用。 |
$avg | $setWindowFields stage. $setWindowFields 阶段中可用。 |
$bottom | $group and $setWindowFields stages. $group 和$setWindowFields 阶段中可用。 |
$bottomN | n fields within a group, according to the specified sort order. $group and $setWindowFields stages. $group 和$setWindowFields 阶段中可用。 |
$count | $count pipeline stage. $count 管道阶段不同。 |
$covariancePop | |
$covarianceSamp | |
$denseRank | $setWindowFields stage partition. $setWindowFields 阶段分区中其他文档的位置(称为排名)。 |
$derivative | |
$documentNumber | $setWindowFields stage partition. $setWindowFields 阶段分区中的位置(称为文档编号)。 |
$expMovingAvg | |
$first | $setWindowFields stage. $setWindowFields 阶段中可用。 |
$integral | |
$last | $setWindowFields stage. $setWindowFields 阶段中可用。 |
$linearFill | null and missing fields in a window using linear interpolationnull 字段和缺失字段。$setWindowFields stage. $setWindowFields 阶段中可用。 |
$locf | null and missing fields in a window to the last non-null value for the field.null 和缺失字段的值设置为该字段的最后一个非null 值。$setWindowFields stage. $setWindowFields 阶段中可用。 |
$max | $setWindowFields stage. $setWindowFields 阶段中可用。 |
$min | $setWindowFields stage. $setWindowFields 阶段中可用。 |
$minN | n minimum valued elements in a group. n 个最小值元素的聚合。$minN array operator. $minN 数组运算符不同。$group , $setWindowFields and as an expression. $group 、$setWindowFields 中可用,用作表达式提供。 |
$push | $setWindowFields stage. $setWindowFields 阶段中可用。 |
$rank | $setWindowFields stage partition. $setWindowFields 阶段分区中其他文档的位置(称为排名)。 |
$shift | $setWindowFields stage partition. $setWindowFields 阶段分区中相对于当前文档的指定位置。 |
$stdDevPop | $setWindowFields stage. $setWindowFields 阶段中可用。 |
$stdDevSamp | $setWindowFields stage. $setWindowFields 阶段中可用。 |
$sum | $setWindowFields stage. $setWindowFields 阶段中可用。 |
$top | $group and $setWindowFields stages. $group 和$setWindowFields 阶段中可用。 |
$topN | n fields within a group, according to the specified sort order. n 个字段的聚合。$group and $setWindowFields stages. $group 和$setWindowFields 阶段中可用。 |
Alphabetical Listing of Expression Operators表达式运算符的字母列表
$abs | |
$accumulator | |
$acos | |
$acosh | |
$add | |
$addToSet | $setWindowFields stage. $setWindowFields 阶段可用。 |
$allElementsTrue | true if no element of a set evaluates to false , otherwise, returns false . false ,则返回true ,否则返回false 。 |
$and | true only when all its expressions evaluate to true . true 时才返回true 。 |
$anyElementTrue | true if any elements of a set evaluate to true ; otherwise, returns false . true ,则返回true ;否则,返回false 。 |
$arrayElemAt | |
$arrayToObject | |
$asin | |
$asinh | |
$atan | |
$atan2 | y / x in radians, where y and x are the first and second values passed to the expression respectively.y/x 的反正切(反正切),其中y 和x 分别是传递给表达式的第一个值和第二个值。 |
$atanh | |
$avg | $setWindowFields stage. $setWindowFields 阶段可用。 |
$binarySize | |
$bitAnd | and operation on an array of int or long values. int 值或long 值数组执行按位and 运算的结果。 |
$bitNot | not operation on a single argument or an array that contains a single int or long value. int 或long 值的数组执行按位not 运算的结果。 |
$bitOr | or operation on an array of int or long values. int 或long 值数组执行按位或运算的结果。 |
$bitXor | xor (exclusive or) operation on an array of int and long values. int 和long 值数组执行按位xor (异或)运算的结果。 |
$bottom | $group and $setWindowFields stages. $group 和$setWindowFields 阶段中可用。 |
$bottomN | n fields within a group, according to the specified sort order. $group and $setWindowFields stages. $group 和$setWindowFields 阶段中可用。 |
$bsonSize | Object ) when encoded as BSON. |
$ceil | |
$cmp | 0 if the two values are equivalent, 1 if the first value is greater than the second, and -1 if the first value is less than the second.0 ;如果第一个值大于第二个值,则返回1 ;如果第一值小于第二个,则返回-1 。 |
$concat | |
$concatArrays | |
$cond | |
$convert | |
$cos | |
$cosh | |
$count | $group and $setWindowFields stages. $group 和$setWindowFields 阶段中可用。$count pipeline stage. $count 管道阶段不同。 |
$covariancePop | $setWindowFields stage. $setWindowFields 阶段可用。 |
$covarianceSamp | $setWindowFields stage. $setWindowFields 阶段可用。 |
$dateAdd | |
$dateDiff | |
$dateFromParts | |
$dateSubtract | |
$dateTrunc | |
$dateToParts | |
$dateFromString | |
$dateToString | |
$dayOfMonth | |
$dayOfWeek | |
$dayOfYear | |
$degreesToRadians | |
$denseRank | $setWindowFields stage. $setWindowFields 阶段可用。 |
$derivative | $setWindowFields stage. $setWindowFields 阶段可用。 |
$divide | |
$documentNumber | $setWindowFields stage. $setWindowFields 阶段可用。 |
$eq | true if the values are equivalent.true 。 |
$exp | |
$expMovingAvg | $setWindowFields stage. $setWindowFields 阶段可用。 |
$filter | |
$first | $setWindowFields stage. $setWindowFields 阶段可用。 |
$firstN | $firstN accumulator. $firstN 累加器不同。 |
$firstN | n fields within a group. n 个字段的聚合。$firstN array operator. $firstN 数组运算符不同。$group , expression and $setWindowFields stages. $group 、表达式和$setWindowFields 阶段中可用。 |
$floor | |
$function | |
$getField | $getField to retrieve the value of fields with names that contain periods (. ) or start with dollar signs ($ ). $getField 来检索名称包含句点(. )或以美元符号($ )开头的字段的值。 |
$gt | true if the first value is greater than the second.true 。 |
$gte | true if the first value is greater than or equal to the second.true 。 |
$hour | |
$ifNull | null 结果,如果第一个表达式导致null 结果,则返回第二个表达式的结果。Null 结果包含未定义值或缺少字段的实例。接受两个表达式作为参数。null 。 |
$in | |
$indexOfArray | |
$indexOfBytes | -1 .-1 。 |
$indexOfCP | -1 .-1 。 |
$integral | $setWindowFields stage. $setWindowFields 阶段可用。 |
$isArray | |
$isNumber | integer 、double 、decimal 或long 之一。 |
$isoDayOfWeek | 1 (for Monday) to 7 (for Sunday).1 (周一)到7 (周日)。 |
$isoWeek | 1 to 53 . Week numbers start at 1 with the week (Monday through Sunday) that contains the year's first Thursday.1 到53 。周数从1 开始,包含一年中第一个星期四的一周(星期一到星期日)。 |
$isoWeekYear | |
$last | $setWindowFields stage. $setWindowFields 阶段可用。 |
$lastN | $lastN accumulator. $lastN 累加器不同。 |
$lastN | n fields within a group. n 个字段的聚合。$lastN array operator. $lastN 数组运算符不同。$group , expression and $setWindowFields stages. $group 、表达式和$setWindowFields 阶段中可用。 |
$let | |
$linearFill | null and missing fields in a window using linear interpolationnull 字段和缺失字段。 |
$literal | $literal expression to a string that starts with a $ to avoid parsing as a field path.$ 开头的字符串使用$literal 表达式,以避免将其解析为字段路径。 |
$ln | |
$locf | null and missing fields in a window to the last non-null value for the field. null 和缺失字段的值设置为该字段的最后一个非null 值。 |
$log | |
$log10 | |
$lt | true if the first value is less than the second.true 。 |
$lte | true if the first value is less than or equal to the second.true 。 |
$ltrim | |
$map | |
$max | $setWindowFields stage. $setWindowFields 阶段可用。 |
$maxN | n largest values in an array. n 个值。$maxN accumulator. $maxN 累加器不同。 |
$maxN | n maximum valued elements in a group. n 个最大值元素的聚合。$maxN array operator. $maxN 数组运算符不同。$group , $setWindowFields and as an expression. $group 、$setWindowFields 中可用,用作表达式。 |
$median | |
$mergeObjects | |
$meta | |
$min | $setWindowFields stage. $setWindowFields 阶段可用。 |
$minN | n smallest values in an array. $minN accumulator. $minN 累加器不同。 |
$minN | n minimum valued elements in a group. $minN array operator. $minN 数组运算符不同。$group , $setWindowFields and as an expression. $group 、$setWindowFields 中可用,用作表达式。 |
$millisecond | |
$minute | |
$mod | |
$month | |
$multiply | |
$ne | true if the values are not equivalent.true 。 |
$not | |
$objectToArray | |
$or | true when any of its expressions evaluates to true . true 时,返回true 。 |
$percentile | |
$pow | |
$push | $setWindowFields stage. $setWindowFields 阶段可用。 |
$radiansToDegrees | |
$rand | |
$range | |
$rank | $setWindowFields stage. $setWindowFields 阶段可用。 |
$reduce | |
$regexFind | |
$regexFindAll | |
$regexMatch | |
$replaceOne | |
$replaceAll | |
$reverseArray | |
$round | |
$rtrim | |
$sampleRate | |
$second | |
$setDifference | |
$setEquals | true if the input sets have the same distinct elements. true 。 |
$setField | $setField to add, update, or remove fields with names that contain periods (. ) or start with dollar signs ($ ). $setField 添加、更新或删除名称包含句点(. )或以美元符号($ )开头的字段。 |
$setIntersection | |
$setIsSubset | true if all elements of the first set appear in the second set, including when the first set equals the second set; i.e. not a strict subsettrue ;即不是严格的子集 |
$setUnion | |
$shift | $setWindowFields stage. $setWindowFields 阶段可用。 |
$size | |
$sin | |
$sinh | |
$slice | |
$sortArray | |
$split | |
$sqrt | |
$stdDevPop | $setWindowFields stage. $setWindowFields 阶段可用。 |
$stdDevSamp | $setWindowFields stage. $setWindowFields 阶段可用。 |
$strcasecmp | 0 if two strings are equivalent, 1 if the first string is greater than the second, and -1 if the first string is less than the second.0 ;如果第一个字符串大于第二个字符串,则返回1 ;如果第一条字符串小于第二个,则返回-1 。 |
$strLenBytes | |
$strLenCP | |
$substr | $substrBytes or $substrCP .$substrBytes 或$substrCP 。 |
$substrBytes | |
$substrCP | |
$subtract | |
$sum | $setWindowFields stage. $setWindowFields 阶段可用。 |
$switch | true , $switch executes a specified expression and breaks out of the control flow.true 的表达式时,$switch 执行指定的表达式并脱离控制流。 |
$tan | |
$tanh | |
$toBool | boolean 。 |
$toDate | Date 。 |
$toDecimal | Decimal128 。 |
$toDouble | double 。 |
$toInt | integer 。 |
$toLong | long 。 |
$toObjectId | ObjectId 。 |
$top | $group and $setWindowFields stages. $group 和$setWindowFields 阶段中可用。 |
$topN | n fields within a group, according to the specified sort order. $group and $setWindowFields stages. $group 和$setWindowFields 阶段中可用。 |
$toString | |
$toLower | |
$toUpper | |
$trim | |
$trunc | |
$tsIncrement | long . long 形式返回时间戳中的递增序号。 |
$tsSecond | long . long 形式返回时间戳中的秒。 |
$type | |
$unsetField | $setField to remove fields with names that contain periods (. ) or that start with dollar signs ($ ). $setField 的别名,用于删除名称中包含句点(. )或以美元符号($ )开头的字段。 |
$week | |
$year | |
$zip |
For the pipeline stages, see Aggregation Pipeline Stages.有关管道阶段,请参阅聚合管道阶段。