对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
See how MongoDB 9.0 delivers up to 2x higher throughput.
MongoDB Branding Shape
Register now >
Docs 菜单

$stdDevPop(表达式)

$stdDevPop

返回大量中数值的总体标准偏差。

注意

消歧

本页描述了用作表达式的 $stdDevPop。

您还可以在其他上下文中使用 $stdDevPop:

用作表达式时,$stdDevPop 采用以下两种语法之一:

{ $stdDevPop: <expression> }

在前面的语法中,操作数是计算结果为大量的单个表达式。 $stdDevPop 遍历大量并返回数组数值的总体标准偏差。

{ $stdDevPop: [ <expression1>, <expression2>, ... ] }

在前面的语法中,每个表达式的计算结果应为单个数值。 $stdDevPop 返回这些值的总体标准差。非数字值将被忽略。

$stdDevPop 以double形式返回输入值的总体标准差。

$stdDevPop 忽略非数字值,包括缺失值。如果所有输入值都是非数字值,则 $stdDevPop 返回 null。

如果输入由单个数值组成,则 $stdDevPop 返回 0。

创建一个 testScores 集合:

db.testScores.insertMany( [
{ studentId: "2345", scores: [ 62, 81, 80, 75, 68, 72, 74, 78, 69, 77 ] },
{ studentId: "2356", scores: [ 60, 83, 79, 72, 65, 71, 68, 74, 64, 76 ] },
{ studentId: "2358", scores: [ 67, 82, 78, 70, 84, 73, 79, 71, 88, 75 ] },
{ studentId: "2367", scores: [ 64, 72, 77, 58, 91, 66, 83, 55, 94, 61 ] },
{ studentId: "2369", scores: [ 60, 53, 72, 85, 63, 88, 57, 79, 66, 74 ] }
] )

以下管道使用 $stdDevPop 计算每个学生测试分数的总体标准偏差:

db.testScores.aggregate( [
{
$project: {
_id: 0,
studentId: 1,
scoreStdDev: {
$stdDevPop: "$scores"
}
}
}
] )

在前面的管道中,带有 $stdDevPop 的 $project 计算每个学生的 scores大量的总体标准偏差,并将其作为 scoreStdDev 返回。

给本页内容打分