原文地址:https://docs.mongodb.com/manual/release-notes/3.2/
New Aggregation Stages
Stage | Description | Syntax |
---|---|---|
$sample | Randomly selects N documents from its input. | { $sample: { size: <positive integer> } } |
$indexStats | Returns statistics on index usage. | { $indexStats: { } } |
$lookup | Performs a left outer join with another collection. |
{
$lookup:
{
from: <collection to join>,
localField: <fieldA>,
foreignField: <fieldB>,
as: <output array field>
}
}
|
New Accumulators(累加器) for $group Stage
Accumulator | Description | Syntax |
---|---|---|
$stdDevSamp | Calculates standard deviation. | { $stdDevSamp: <array> } |
$stdDevPop | Calculates population standard deviation. | { $stdDevPop: <array> } |
New Aggregation Arithmetic Operators
Operator | Description | Syntax |
---|---|---|
$sqrt | Calculates the square root. | { $sqrt: <number> } |
$abs | Returns the absolute value of a number. | { $abs: <number> } |
$log | Calculates the log of a number in the specified base. | { $log: [ <number>, <base> ] } |
$log10 | Calculates the log base 10 of a number. | { $log10: <number> } |
$ln | Calculates the natural log of a number. | { $ln: <number> } |
$pow | Raises a number to the specified exponent(指数). | { $pow: [ <number>, <exponent> ] } |
$exp | Raises e to the specified exponent. | { exp: <number> } |
$trunc | Truncates(截取) a number to its integer. | { $trunc: <number> } |
$ceil | Returns the smallest integer greater than or equal to the specified number. | { $ceil: <number> } |
$floor | Returns the largest integer less than or equal to the specified number. | { floor: <number> } |
New Aggregation Array Operators
Operator | Description | Syntax |
---|---|---|
$slice | Returns a subset of an array. | { $slice: [ <array>, <n> ] } or { $slice: [ <array>, <position>, <n> ] } |
$arrayElemAt | Returns the element at the specified array index. | { $arrayElemAt: [ <array>, <idx> ] } |
$concatArrays | Concatenates(串联) arrays. |
{
$concatArrays: [ <array1>, <array2>, ... ]
}
|
$isArray | Determines if the operand is an array. | { $isArray: [ <expression> ] } |
$filter | Selects a subset of the array based on the condition. |
{
$filter:
{
input: <array>,
as: <string>,
cond: <expression>
}
}
|