On this page本页内容
$stdDevPop¶New in version 3.2.版本3.2中的新功能。
Calculates the population standard deviation of the input values. 计算输入值的总体标准偏差。Use if the values encompass the entire population of data you want to represent and do not wish to generalize about a larger population. 如果这些值包含要表示的整个数据总体,并且不希望泛化更大的总体,则使用。$stdDevPop ignores non-numeric values.$stdDevPop忽略非数值。
If the values represent only a sample of a population of data from which to generalize about the population, use 如果这些值仅代表总体数据的一个样本,可以从中概括总体,请改用$stdDevSamp instead.$stdDevSamp。
$stdDevPop is available in the in the following stages:可在以下阶段在中获得:
$group$project$addFields$set$replaceRoot$replaceWith$match stage that includes an $expr expression$expr表达式的$match阶段When used in the 语法如下所示:$group stage, $stdDevPop returns the population standard deviation of the specified expression for a group of documents that share the same group by key and has the following syntax:在$group阶段中使用时,$stdDevPop返回一组文档的指定表达式的总体标准偏差,这些文档按键共享同一组,并且具有以下语法:
$stdDevPopWhen used in the other supported stages, 在其他受支持的阶段中使用时,$stdDevPop returns the standard deviation of the specified expression or list of expressions for each document and has one of two syntaxes:$stdDevPop返回每个文档的指定表达式或表达式列表的标准偏差,并具有以下两种语法之一:
$stdDevPop$stdDevPopThe argument for $stdDevPop can be any expression as long as it resolves to an array. $stdDevPop的参数可以是任何表达式,只要它解析为数组。For more information on expressions, see Expressions有关表达式的详细信息,请参阅表达式
$stdDevPop ignores non-numeric values. If all operands for a $stdDevPop are non-numeric, $stdDevPop returns null.
If the sample consists of a single numeric value, 如果样本由单个数值组成,$stdDevPop returns 0.$stdDevPop返回0。
In the $group stage, if the expression resolves to an array, $stdDevPop treats the operand as a non-numerical value.
In the other supported stages:
$stdDevPop traverses into the array to operate on the numerical elements of the array to return a single value.$stdDevPop does not traverse into the array but instead treats the array as a non-numerical value.$group Stage¶A collection named users contains the following documents:
The following example calculates the standard deviation of each quiz:
The operation returns the following results:操作返回以下结果:
$project Stage¶Create an example collection named quizzes with the following documents:
The following example calculates the standard deviation of each quiz:
The operation returns the following results:操作返回以下结果: