$isoWeek is a MongoDB aggregation expression that returns the ISO 8601 week number (1–53) for a date. ISO weeks start on Monday. Week 1 is the week that contains the year’s first Thursday.
Remember
$isoWeek = ISO week number (1…53)
{ $isoWeek: <dateExpression> }
or
{ $isoWeek: { date: <date>, timezone: "<tz>" } }
weeks start Monday
week 1 contains first Thursday of the year
null / missing → null
pair with $isoWeekYear for reports
Pass a Date field (for example "$orderDate") to $isoWeek.
Optionally set timezone when the local calendar day matters.
Add $isoWeekYear when you need a stable year-week key for grouping.
Piece
Required?
Role
Date expression
Yes
Source Date to inspect
timezone
No
Interpret the date in a named zone
$isoWeekYear
No
Correct year half of an ISO week key
Pseudocode
Pseudocode
for each document:
d = evaluate(dateExpression)
if d is null or missing:
result = null
else:
result = ISO_8601_week_number(d) // 1..53
emit { ..., field: result }
Reference
Cheat Sheet
Keep these facts handy while extracting ISO weeks.
Topic
Detail
Type
Aggregation expression (not a find filter)
Syntax
{ $isoWeek: <date> }
Range
1 to 53
Week start
Monday
Week 1 rule
Contains first Thursday / Jan 4
vs $week
$week is Sunday-based
Sample check
2026-01-12 (Mon) → ISO week 3
Try it
Live Preview
Watch $isoWeek turn a date into an ISO week number.
Simulates { $isoWeek: date } in UTC.
Result
date = 2026-01-12T00:00:00.000Z
$isoWeek → 3
{ isoWeek: 3 }
Trace
Worked Walkthrough — Order Week
An order was placed on Monday, 2026-01-12. Which ISO week is that?
We use one order date. First extract the ISO week, then also extract the ISO week-year for a complete week key. Run these in mongosh after inserting the sample data once.
Example 1 — Sample Data
Imagine one order placed on 2026-01-12 (a Monday). We save it in a collection named orders.
Same stored document. Still using orderDate: 2026-01-12 from Example 1.
Week + year together.$isoWeekYear supplies the year half of the ISO week key.
Easy report label. You can group as 2026-W03 without mixing calendar-year edge cases.
Edge Cases & Pitfalls
Check these before using $isoWeek in production pipelines.
year
Do not pair with calendar $year alone
Early January / late December can belong to a different ISO week-year. Use $isoWeekYear.
vs week
$week is not the same
$week uses Sunday-based numbering. Pick one convention and stay consistent.
tz
Timezone can change the day
A UTC evening may be the next local morning. Set timezone when reports follow a local calendar.
null
Null dates stay null
Missing or null dates return null, not an error. Validate dates before grouping by week.
Analysis
Performance Notes
Approach
Cost
Best for
$isoWeek per document
Cheap date extract
Weekly labels on the fly
Group by week
Extract + group
Weekly rollups
Store week on write
No recompute
Hot weekly dashboards
Week extraction is cheap. Filter early with $match when only some documents need a week number.
Remember
Key Takeaways
Role: ISO 8601 week number (1–53).
Start day: Monday (not Sunday).
Pairing: use $isoWeekYear for report keys.
Sibling:$week is a different convention.
One line:$isoWeek answers “which ISO week is this date in?”—Monday-start weeks, numbered 1–53.
Frequently Asked Questions
$isoWeek returns the ISO 8601 week number (1–53) for a date. Use it inside aggregation stages such as $project, $addFields, and $group.
Use { $isoWeek: <dateExpression> }, or { $isoWeek: { date: <dateExpression>, timezone: <tz> } }. Pass a Date field, ISODate literal, or any expression that resolves to a date.
ISO weeks start on Monday. Week 1 is the week that contains the year’s first Thursday (also the week containing January 4). Near year boundaries, a date may belong to week 52/53 of the previous ISO year or week 1 of the next.
Yes for reporting keys. Calendar year and ISO week-year can differ in late December / early January. Use both for a correct year-week label.
$isoWeek follows ISO 8601 (Monday start). $week uses a Sunday-based week numbering that can differ for the same date.
$isoWeek returns null when the input is null or the field is missing.