The $stdDevPop accumulator measures population standard deviation in each $group bucket—how far numeric values typically spread from their average. Use it when the grouped data represents the complete population you care about.
01
Spread per group
Population std dev.
02
Simple syntax
{ $stdDevPop: "$field" }
03
vs $stdDevSamp
Population vs sample.
04
+ $avg
Mean and spread together.
05
Non-numeric skipped
Null and strings ignored.
06
Single value → 0
No spread with one point.
Fundamentals
Definition and Usage
$stdDevPop is a MongoDB accumulator used in the $group stage. For each group, it evaluates a numeric expression on every document and returns the population standard deviation—a measure of how much values vary from their mean.
💡
Beginner tip
Think of $avg as “where is the center?” and $stdDevPop as “how scattered are the numbers?” Low std dev means scores cluster tightly; high std dev means wide spread.
Use $stdDevPop when your group contains all data you want to describe (every student in a class, every sale in a store for the month). When values are only a sample meant to represent a larger population, use $stdDevSamp instead.
$stdDevPop adds statistical spread to your aggregation reports. Use it when each $group bucket represents a complete population, and pair it with $avg for mean-and-variability summaries.
When data is only a sample of a larger population, switch to $stdDevSamp. For simple range checks, $min and $max may be enough.
Use $stdDevPop when the group contains the full population you analyze
Combine $avg + $stdDevPop + $sum: 1 for complete stats
Filter non-numeric junk with $match before $group when data is messy
Round output with $round for human-readable dashboards
Choose $stdDevSamp when inferring about a larger population from a subset
❌ Don’t
Confuse population ($stdDevPop) with sample ($stdDevSamp) formulas
Expect meaningful spread from groups with only one or two numeric values without context
Pass array fields directly in $group—they are ignored as non-numeric
Compare std dev across groups with very different N without also showing counts
Use std dev on non-numeric categorical data—filter to numbers first
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about $stdDevPop
Use these points when measuring numeric spread inside $group.
5
Core concepts
📊01
Population σ
Spread per group.
Basics
📝02
Simple syntax
{ $stdDevPop: "$field" }
Syntax
📈03
vs $stdDevSamp
N vs N−1 divisor.
Compare
💲04
+ $avg
Mean and spread.
Pair
🔢05
One value → 0
No spread alone.
Edge case
❓ Frequently Asked Questions
$stdDevPop calculates the population standard deviation of numeric values in each $group bucket. It measures how spread out the values are around their mean, treating the grouped data as the entire population.
Inside $group: { spread: { $stdDevPop: "$score" } }. It also works in $project, $addFields, and window stages—but this tutorial focuses on the $group accumulator.
$stdDevPop divides by N (population formula). $stdDevSamp divides by N−1 (sample formula) when you want to estimate spread for a larger population. Use $stdDevPop when your group is the complete dataset.
Non-numeric values—including null, missing fields, strings, and objects—are ignored. If no numeric values exist in a group, $stdDevPop returns null.
$stdDevPop returns 0. With a single data point there is no spread around the mean.
$avg returns the mean (center). $stdDevPop returns the population standard deviation (spread). Pair both in one $group for mean-and-variability reports.
Did you know?
Population standard deviation divides by N; sample standard deviation ($stdDevSamp) divides by N−1 (Bessel’s correction) to better estimate spread when your data is a subset. For three scores 85, 90, and 71, both formulas happen to yield ~8.04—but they diverge as group size grows. See the official $stdDevPop docs.