MongoDB $isoDayOfWeek Operator

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

What Is $isoDayOfWeek?

$isoDayOfWeek is a MongoDB aggregation expression that returns the ISO 8601 weekday number for a date: Monday = 1 … Sunday = 7. By default the day is in UTC; you can pass an optional timezone.

Remember
$isoDayOfWeek = ISO weekday (Mon=1 … Sun=7)

{ $isoDayOfWeek: <dateExpression> }

{ $isoDayOfWeek: { date: <date>, timezone: <tz> } }

input  → Date / Timestamp / ObjectId  (not a string)
default → UTC
output → 1 … 7

Mon=1 Tue=2 Wed=3 Thu=4 Fri=5 Sat=6 Sun=7
UsePrefer
ISO weekday (Mon=1)$isoDayOfWeek
Sunday-based weekday$dayOfWeek
ISO week number$isoWeek

How to Use $isoDayOfWeek in MongoDB

Point it at a date field, then choose UTC or a timezone for the weekday.

  1. Choose an expression stage ($addFields or $project).
  2. Pass a Date field (or expression) to $isoDayOfWeek.
  3. Optional: use { date, timezone } for a local weekday (Olson name or UTC offset).
  4. Use the integer in filters, groups, or labels (for example weekday vs weekend).
PieceRequired?Role
$isoDayOfWeekYesExtract ISO weekday 1–7
Date expressionYesDate, Timestamp, or ObjectId
timezoneNoOlson id or offset; default UTC

Pseudocode

Pseudocode
for each document:
    d = evaluate(dateExpression)
    if timezone provided:
        local = convert(d, timezone)
        result = iso_weekday(local)     // 1–7, Mon=1
    else:
        result = iso_weekday(d in UTC)  // 1–7, Mon=1
    emit { ..., field: result }

Cheat Sheet

Keep these facts handy while extracting ISO weekdays.

TopicDetail
TypeAggregation date expression (not a find filter alone)
Simple syntax{ $isoDayOfWeek: "$at" }
With timezone{ $isoDayOfWeek: { date: "$at", timezone: "-05:00" } }
Range1 (Monday) to 7 (Sunday)
Default zoneUTC
vs $dayOfWeekISO Mon=1 vs Sunday=1
Not allowedPlain date strings — convert to Date first

Live Preview

Pick a UTC date and see the ISO weekday number (Monday = 1 … Sunday = 7).

Simulates default UTC $isoDayOfWeek (same idea as the mongosh examples).

Result
at = 2024-01-01T12:00:00Z
$isoDayOfWeek → 1 (Monday)

{ isoDay: 1, name: "Monday" }

Worked Walkthrough — Mon / Wed / Sun

Three dates in January 2024. ISO numbering starts the week on Monday.

Calculation
ISO map: Mon=1 Tue=2 Wed=3 Thu=4 Fri=5 Sat=6 Sun=7

2024-01-01 (Monday)  → 1
2024-01-03 (Wednesday) → 3
2024-01-07 (Sunday)  → 7

Timezone tip (near midnight):
  2024-01-01T02:00:00Z → UTC Monday → 1
  same instant, timezone "-05:00" → previous evening Sunday → 7

Timezone can change the weekday number without changing the stored instant.

MongoDB Examples

We use a small events collection with UTC dates. First we extract the ISO weekday, then we show how timezone can flip the day near midnight. Insert the sample data once in mongosh.

Example 1 — Sample Data

Imagine three events stored as BSON dates in UTC. We save them in a collection named events.

mongosh
db.events.insertMany([
  { _id: 1, name: "Kickoff", at: ISODate("2024-01-01T12:00:00Z") },
  { _id: 2, name: "Early UTC", at: ISODate("2024-01-01T02:00:00Z") },
  { _id: 3, name: "Wrap-up", at: ISODate("2024-01-07T12:00:00Z") }
]);

How the Data Is Stored in MongoDB

After the insert, MongoDB keeps three documents in events. Run find() to see them:

mongosh
db.events.find()

Read those documents like this:

Field in MongoDBExamplePlain English
_id1Event id for this lesson
name"Kickoff"Event label
atISODate("2024-01-01T12:00:00Z")When it happens (UTC)
Picture
ISO weekdays (UTC):

  Kickoff   2024-01-01 noon  → Monday → 1
  Early UTC 2024-01-01 02:00 → Monday → 1
  Wrap-up   2024-01-07 noon  → Sunday → 7

Early UTC is useful later: with timezone -05:00 it becomes Sunday.

How It Works

  1. Insert once. insertMany adds three event documents with real BSON dates.
  2. Use ISODate(...). Strings alone are not valid input for $isoDayOfWeek.
  3. find() shows the same shape. What you inserted is what you get back—ready for the next examples.

Example 2 — Weekday in UTC

Goal: add iso_day using the default UTC calendar day.

mongosh
db.events.aggregate([
  {
    $addFields: {
      iso_day: { $isoDayOfWeek: "$at" }
    }
  }
]);

How It Works

  1. Read the stored date. "$at" is already a BSON Date.
  2. Default zone is UTC. No timezone option → use the UTC calendar day.
  3. Map to 1–7. Both Jan 1 events are Monday → 1; Wrap-up is Sunday → 7.
  4. Keep all fields. $addFields adds iso_day next to the original document.

Example 3 — Weekday With Timezone

Take Early UTC (2024-01-01T02:00:00Z). In UTC it is Monday; with -05:00 it is still Sunday evening.

mongosh
db.events.aggregate([
  { $match: { _id: 2 } },
  {
    $addFields: {
      iso_day_utc: { $isoDayOfWeek: "$at" },
      iso_day_minus5: {
        $isoDayOfWeek: {
          date: "$at",
          timezone: "-05:00"
        }
      }
    }
  }
]);

How It Works

  1. Same stored document. Early UTC from Example 1: 2024-01-01T02:00:00Z.
  2. UTC weekday. $isoDayOfWeek: "$at" → Monday → 1.
  3. Apply -05:00. Local clock becomes 2023-12-31 21:00 → Sunday → 7.
  4. Same stored moment, different day number. Always choose the timezone your report means.

Edge Cases & Pitfalls

Check these before using $isoDayOfWeek in production pipelines.

iso

Monday is 1, not Sunday

Do not mix with $dayOfWeek (Sunday=1). Weekend checks differ: ISO weekend is 6 and 7.

string

Strings are not dates

"2024-01-01" errors. Store BSON dates or convert with $dateFromString / $toDate first.

tz

Timezone can flip the day

Near UTC midnight, another offset may land on the previous or next weekday. Set timezone when reports are local.

null

Null / missing → null

Missing date fields return null, not an error. Guard with $ifNull if needed.

Performance Notes

ApproachCostBest for
$isoDayOfWeekPer-document date mathWeekday labels / filters
+ timezoneSlightly more workLocal business calendars
Group by weekdayO(docs) + groupTraffic by day of week

Date-part extraction is cheap compared with large sorts or joins. Filter early with $match when only some documents need a weekday.

Key Takeaways

  • Role: ISO weekday number, Monday = 1 through Sunday = 7.
  • Default: UTC unless you set timezone.
  • Not $dayOfWeek: that one starts on Sunday.
  • Input: Date / Timestamp / ObjectId — not a plain string.

One line: $isoDayOfWeek answers “which ISO weekday is this date?”—1 for Monday through 7 for Sunday.

Frequently Asked Questions

$isoDayOfWeek returns an integer from 1 to 7 for the ISO 8601 weekday of a date. Monday is 1, Tuesday is 2, through Sunday which is 7. Use it inside aggregation stages such as $project and $addFields.
Simple form: { $isoDayOfWeek: <dateExpression> }. With timezone: { $isoDayOfWeek: { date: <dateExpression>, timezone: <tz> } }. The date must be a Date, Timestamp, or ObjectId—not a string.
$isoDayOfWeek follows ISO 8601 (Monday=1, Sunday=7). $dayOfWeek uses Sunday=1 through Saturday=7. The same date can return different numbers.
By default it uses UTC. Pass timezone (Olson name or UTC offset) to get the weekday in another zone—near midnight this can change the day number.
No. Convert strings to dates first (for example with $dateFromString or $toDate), then pass that date to $isoDayOfWeek.
$isoDayOfWeek returns null when the input is null or the field is missing. It does not throw an error.

Next: $isoWeek

Get the ISO 8601 week number for a date.

$isoWeek tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful