The $dayOfWeek operator extracts the weekday as an integer from 1 to 7 inside MongoDB aggregation pipelines. Use it to filter weekend traffic, compare Monday vs Friday sales, or group events by weekday pattern.
01
Extract Weekday
Date → integer 1–7.
02
Syntax
One date argument.
03
Sunday = 1
MongoDB numbering.
04
UTC Default
Uses UTC calendar.
05
Use Cases
Weekends, weekdays.
06
vs $isoDayOfWeek
Different numbering.
Fundamentals
Definition and Usage
In MongoDB’s aggregation framework, the $dayOfWeek operator takes a date expression and returns an integer from 1 to 7. MongoDB numbers weekdays with Sunday = 1 through Saturday = 7. For example, $dayOfWeek on ISODate("2024-06-15T00:00:00Z") (a Saturday) returns 7.
💡
Beginner Tip
Do not assume Monday = 1. MongoDB’s $dayOfWeek starts the week on Sunday. For ISO-style numbering (Monday = 1), use $isoDayOfWeek instead.
Foundation
📝 Syntax
The $dayOfWeek operator takes a single date expression:
mongosh
{ $dayOfWeek: <dateExpression> }
Syntax Rules
Argument — any expression that evaluates to a BSON Date.
Return value — integer 1 (Sunday) through 7 (Saturday) in UTC.
Null input — returns null when the date is null or missing.
Use inside $project, $addFields, $match with $expr, or $group.
Weekday Number Reference
1 — Sunday
2 — Monday
3 — Tuesday
4 — Wednesday
5 — Thursday
6 — Friday
7 — Saturday
💡 $dayOfWeek vs $isoDayOfWeek vs $dayOfMonth
$dayOfWeek — Sunday = 1, Saturday = 7
$isoDayOfWeek — Monday = 1, Sunday = 7 (ISO 8601)
$dayOfMonth — day of month 1–31, not weekday
Cheat Sheet
⚡ Quick Reference
Question
Answer
Operator type
Aggregation expression operator (date extraction)
Arguments
One date expression
Return type
Integer (1–7)
Week starts on
Sunday (= 1)
MongoDB version
3.4+
From field
{ $dayOfWeek: "$orderDate" }
Weekday of orderDate
Saturday
{ $dayOfWeek: ISODate("2024-06-15") }
Returns 7
Weekend filter
{ $in: [
{ $dayOfWeek: "$d" },
[1, 7]
]}
Sun or Sat
Monday only
{ $eq: [
{ $dayOfWeek: "$d" },
2
]}
Monday = 2
Hands-On
Examples Gallery
Extract weekday numbers, filter weekend orders, find Monday activity, and analyze sales by day of week with $dayOfWeek.
📚 Extract the Weekday from a Date
Use an orders collection and add a weekday number from orderDate.
Sample Input Documents
Suppose you have an orders collection with order timestamps:
Weekend detection in MongoDB uses [1, 7] with $dayOfWeek, not Saturday/Sunday as 6 and 7 in ISO numbering. Double-check your operator before writing filters.
Example 3 — Find Monday Transactions
Filter documents where the event occurred on a Monday (weekday = 2):
Grouping by $dayOfWeek aggregates all Sundays across every week into one bucket. Add $week or $year to _id when you need per-week breakdowns.
Applications
🚀 Use Cases
Retail analytics — compare weekday vs weekend purchase volume.
Support staffing — find which weekdays generate the most tickets.
Marketing schedules — target campaigns on high-traffic weekdays.
Compliance windows — filter events that must occur on business days (Mon–Fri).
🧠 How $dayOfWeek Works
1
MongoDB resolves the date
The input expression is evaluated per document — a field, $$NOW, or literal ISODate.
Input
2
$dayOfWeek maps to 1–7
MongoDB determines the weekday in UTC using Sunday = 1 through Saturday = 7.
Extract
3
An integer is returned
The number is ready for $match, $group, or conditional logic in pipelines.
Output
=
📅
Weekday number for queries
Combine with $dayOfMonth, $month, or $isoDayOfWeek for richer calendar logic.
Wrap Up
Conclusion
The $dayOfWeek operator is a simple way to extract weekday numbers from BSON dates in MongoDB aggregation pipelines. Its Sunday-first numbering is the main detail beginners must remember when writing weekend or weekday filters.
For ISO Monday-first numbering, use $isoDayOfWeek. For timezone-aware weekdays, use $dateToParts with a timezone field. Next in the series: $dayOfYear for day-of-year extraction.
Use $isoDayOfWeek when your team expects ISO numbering
Filter weekends with $in: [1, 7]
Store BSON dates for reliable weekday extraction
Document numbering in shared query libraries
❌ Don’t
Assume Monday = 1 with $dayOfWeek
Confuse $dayOfWeek with $dayOfMonth
Forget UTC vs local time near midnight boundaries
Mix $dayOfWeek and $isoDayOfWeek in one dashboard without labels
Parse string dates — convert with $dateFromString first
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about $dayOfWeek
Use these points when extracting weekdays from dates in MongoDB.
5
Core concepts
📅01
Extract Weekday
Date → 1–7.
Purpose
📝02
One Argument
Date expression.
Syntax
🛠03
Sunday = 1
Key numbering rule.
Output
🌐04
UTC Calendar
Default timezone.
Note
⚠05
Not $isoDayOfWeek
Monday-first vs Sun-first.
Important
❓ Frequently Asked Questions
$dayOfWeek returns an integer from 1 to 7 representing the day of the week for a BSON Date. In MongoDB, 1 is Sunday, 2 is Monday, through 7 is Saturday.
{ $dayOfWeek: <dateExpression> }. Pass a field reference like "$orderDate", a literal ISODate, or another expression that evaluates to a date.
MongoDB uses 1 = Sunday, 2 = Monday, 3 = Tuesday, 4 = Wednesday, 5 = Thursday, 6 = Friday, 7 = Saturday. This differs from $isoDayOfWeek, where Monday = 1 and Sunday = 7.
$dayOfWeek extracts the weekday in UTC. For a specific timezone, use $dateToParts with a timezone field and read isoDayOfWeek, or use $isoDayOfWeek with timezone-aware date handling.
$dayOfWeek is available in MongoDB 3.4 and later in aggregation pipelines and update pipelines that use aggregation expressions.