$isoDayOfWeek (ISO Day of Week)
Last updated: 2026-10-09
$isoDayOfWeek (ISO Day of Week)
$isoDayOfWeek returns the weekday number per ISO 8601: 1 is Monday, 7 is Sunday — unlike $dayOfWeek where Sunday is 1. Pair it with $isoWeek and $isoWeekYear for week-level stats that follow the international standard. It returns an integer; timezone drives the weekday boundary and defaults to UTC (pass Asia/Shanghai for China-based data).
| Category | Date |
|---|---|
| MongoDB Version | 1.0+ |
| Example Language | mongosh (Shell) |
📝 Syntax
{ $isoDayOfWeek: { date: <date-expression>, timezone: <timezone> } }
⚙️ Parameters
| date | Required; the date expression. |
|---|---|
| timezone | Optional timezone; defaults to UTC. |
Returns:ISO weekday (1=Monday, 7=Sunday); null if date is null.
▶ Example
Run the commands below in your local mongosh (requires a running mongod):
// $isoDayOfWeek: sales by ISO weekday (Beijing time)
db.sales.aggregate([
{ $group: {
_id: { $isoDayOfWeek: { date: '$soldAt', timezone: 'Asia/Shanghai' } },
total: { $sum: '$amount' }
} }
])
Output:
{ "_id": 1, "total": 3200 }
{ "_id": 2, "total": 2750 }
📌 Notes
- Off by one from $dayOfWeek: Monday is 2 there, 1 here
- Usually combined with $isoWeek and $isoWeekYear
- Defaults to UTC — unify timezone before stats
🏷️ Related Tags
💡 Related Cases
More hands-on cases coming soon.
📚 Related Tutorials
❓ FAQ
QIs 1 Monday or Sunday?
APer ISO 8601: 1 is Monday, 7 is Sunday.
QHow far is this from $dayOfWeek?
ASame date differs by one: $dayOfWeek's 2 equals $isoDayOfWeek's 1.
QDoes timezone change the weekday?
AYes — times near midnight can flip to another day; unify timezone.