$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.
| Category | Accumulators |
|---|---|
| MongoDB Version | 3.2+ |
| Example Language | mongosh (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
- Population stddev divides by N; sample stddev by N-1
- Null and non-numeric values are ignored
- Returns null when a group has no numeric values
🏷️ Related Tags
💡 Related Cases
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.