$stdDevPop (Population StdDev Accumulator)

Last updated: 2026-10-09

$stdDevPop (Population StdDev Accumulator)

$stdDevPop is an accumulator computing the population standard deviation of a field across a group, dividing by N rather than N-1. Use it when data represents the entire population, e.g. a whole school's scores. Non-numeric values are ignored. The only difference from $stdDevSamp is the denominator.

CategoryAccumulators
MongoDB Version3.2+
Example Languagemongosh (Shell)

📝 Syntax

{ $group: { _id: <key>, dev: { $stdDevPop: "$field" } } }

Returns:Population standard deviation (non-numeric values ignored)

▶ Example

Run the commands below in your local mongosh (requires a running mongod):

// $stdDevPop: population stddev of scores per class
db.scores.aggregate([
  { $group: { _id: '$class', dev: { $stdDevPop: '$score' } } }
])

Output:

{ "_id": "A", "dev": 12.34 }

📌 Notes

More hands-on cases coming soon.

📚 Related Tutorials

❓ FAQ

QWhat is the difference between $stdDevPop and $stdDevSamp?
A$stdDevPop treats data as the whole population (N); $stdDevSamp treats it as a sample (N-1).
QWhen should I use $stdDevPop?
AWhen data covers the entire population, like a whole school's scores rather than a sample.
QWhat if a group has only non-numeric values?
AIt returns null.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏