MongoDB $isoDayOfWeek Operator

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 4 Examples
Date Operations

What You’ll Learn

The $isoDayOfWeek operator extracts the weekday as an integer using the ISO 8601 calendar (Monday = 1 through Sunday = 7). Use it in aggregation pipelines to filter weekend orders, group sales by weekday, or label business vs non-business days.

01

ISO Weekday

Date → integer 1–7.

02

Syntax

One date argument.

03

Monday = 1

ISO 8601 numbering.

04

$project Stage

Add weekday fields.

05

Use Cases

Weekends, reporting.

06

vs $dayOfWeek

Different numbering.

Definition and Usage

In MongoDB’s aggregation framework, the $isoDayOfWeek operator takes a date expression and returns an integer from 1 to 7 following the ISO 8601 standard. Monday = 1, Tuesday = 2, and Sunday = 7. For example, $isoDayOfWeek on ISODate("2024-06-17T00:00:00Z") (a Monday) returns 1.

ISO weekday numbering is common in business reporting, analytics dashboards, and international systems where the week starts on Monday. Pair $isoDayOfWeek with $isoWeek and $isoWeekYear for full ISO calendar analysis.

💡
Beginner Tip

Do not confuse $isoDayOfWeek with $dayOfWeek. MongoDB’s $dayOfWeek starts the week on Sunday (Sunday = 1). $isoDayOfWeek starts on Monday (Monday = 1). The same date can return different numbers.

📝 Syntax

The $isoDayOfWeek operator takes a single date expression:

mongosh
{ $isoDayOfWeek: <dateExpression> }

Syntax Rules

  • Argument — any expression that evaluates to a BSON Date.
  • Return value — integer 1 (Monday) through 7 (Sunday) in UTC.
  • Null input — returns null when the date is null or missing.
  • Use inside $project, $addFields, $match with $expr, or $group.

ISO Weekday Number Reference

  • 1 — Monday
  • 2 — Tuesday
  • 3 — Wednesday
  • 4 — Thursday
  • 5 — Friday
  • 6 — Saturday
  • 7 — Sunday

💡 $isoDayOfWeek vs $dayOfWeek

The same date can return different weekday numbers:

2024-06-17 (Monday)$isoDayOfWeek = 1, $dayOfWeek = 2
2024-06-15 (Saturday)$isoDayOfWeek = 6, $dayOfWeek = 7
2024-06-16 (Sunday)$isoDayOfWeek = 7, $dayOfWeek = 1

⚡ Quick Reference

QuestionAnswer
Operator typeAggregation expression operator (date extraction)
Syntax{ $isoDayOfWeek: <dateExpression> }
Return typeInteger 1–7 (ISO weekday)
Week starts onMonday (ISO 8601)
Common stages$project, $addFields, $group, $match + $expr
Field
{
  $isoDayOfWeek: "$orderDate"
}

Weekday from field

Literal date
{
  $isoDayOfWeek: ISODate(
    "2024-06-17"
  )
}

Returns 1 (Monday)

Weekend check
{
  $in: [
    { $isoDayOfWeek: "$date" },
    [6, 7]
  ]
}

Sat or Sun (ISO)

Null input
{
  $isoDayOfWeek: null
}

Returns null

Examples Gallery

Walk through sample order data, extract ISO weekday numbers with $project, filter weekends, and group sales by day of week.

📚 Extract ISO Weekday

Start with an orders collection and add an ISO weekday number to each document.

Sample Input Documents

Suppose you have an orders collection with orderDate and amount fields:

mongosh
[
  { "_id": ObjectId("609c26812e9274a86871bc6a"), "orderDate": ISODate("2024-06-17T14:30:00Z"), "amount": 120 },
  { "_id": ObjectId("609c26812e9274a86871bc6b"), "orderDate": ISODate("2024-06-15T10:00:00Z"), "amount": 85 },
  { "_id": ObjectId("609c26812e9274a86871bc6c"), "orderDate": ISODate("2024-06-16T18:45:00Z"), "amount": 200 }
]

June 17, 2024 is a Monday, June 15 is Saturday, and June 16 is Sunday.

Example 1 — Basic $isoDayOfWeek on a Field

Add an isoWeekday field to each order:

mongosh
db.orders.aggregate([
  {
    $project: {
      orderDate: 1,
      amount: 1,
      isoWeekday: {
        $isoDayOfWeek: "$orderDate"
      }
    }
  }
])

How It Works

  • ISO numbering: Monday = 1, Saturday = 6, Sunday = 7.
  • The result is based on the UTC calendar date of the stored ISODate.
  • Compare with $dayOfWeek — the same Monday would return 2 there (Sunday-based week).

📈 Practical Patterns

Filter weekend orders, label business days, and aggregate revenue by ISO weekday.

Example 2 — Filter Weekend Orders

Find orders placed on Saturday (6) or Sunday (7) using $match and $expr:

mongosh
db.orders.aggregate([
  {
    $match: {
      $expr: {
        $in: [
          { $isoDayOfWeek: "$orderDate" },
          [6, 7]
        ]
      }
    }
  },
  {
    $project: {
      orderDate: 1,
      amount: 1,
      isoWeekday: {
        $isoDayOfWeek: "$orderDate"
      }
    }
  }
])

How It Works

$in checks whether the ISO weekday is 6 or 7. This is a clean way to isolate weekend activity without parsing date strings manually.

Example 3 — Label Weekday vs Weekend with $cond

Add a human-readable dayType field:

mongosh
db.orders.aggregate([
  {
    $project: {
      orderDate: 1,
      amount: 1,
      dayType: {
        $cond: [
          {
            $lte: [
              { $isoDayOfWeek: "$orderDate" },
              5
            ]
          },
          "weekday",
          "weekend"
        ]
      }
    }
  }
])

How It Works

ISO weekdays 1 through 5 are Monday to Friday. Values 6 and 7 are Saturday and Sunday. $lte with 5 cleanly separates business days from weekends.

Example 4 — Group Sales by ISO Weekday

Summarize total revenue for each day of the week:

mongosh
db.orders.aggregate([
  {
    $group: {
      _id: {
        $isoDayOfWeek: "$orderDate"
      },
      totalAmount: { $sum: "$amount" },
      orderCount: { $sum: 1 }
    }
  },
  {
    $sort: { _id: 1 }
  }
])

How It Works

Using $isoDayOfWeek as the $group key buckets orders by weekday number. Sort by _id to display Monday through Sunday in order.

Bonus — Compare $isoDayOfWeek and $dayOfWeek

See both numbering systems side by side on the same date:

mongosh
db.orders.aggregate([
  {
    $project: {
      orderDate: 1,
      isoWeekday: {
        $isoDayOfWeek: "$orderDate"
      },
      mongoWeekday: {
        $dayOfWeek: "$orderDate"
      }
    }
  }
])

How It Works

On Monday June 17, 2024: isoWeekday is 1 but mongoWeekday is 2. Always confirm which operator your reports and dashboards expect before building filters.

🚀 Use Cases

  • Weekend vs weekday analysis — filter or label orders, logins, or events by ISO business days.
  • Sales reporting — group revenue by weekday to spot Monday spikes or Friday dips.
  • Scheduling logic — route jobs or notifications differently on Saturdays and Sundays.
  • ISO calendar pipelines — combine with $isoWeek and $isoWeekYear for standard week-based reports.

🧠 How $isoDayOfWeek Works

1

MongoDB reads the date expression

The pipeline evaluates the input — a field like "$orderDate" or an ISODate literal.

Input
2

$isoDayOfWeek maps to ISO weekday

MongoDB converts the UTC calendar date to an integer 1–7 using ISO 8601 rules (Monday = 1, Sunday = 7).

Extract
3

The number is stored in the pipeline

The weekday integer is written to your output field or used as a $group key for aggregation.

Output
=

ISO weekday data

You get standard weekday numbers ready for filtering, labeling, and grouped reports.

Conclusion

The $isoDayOfWeek operator is the right choice when you need ISO 8601 weekday numbers in MongoDB aggregation pipelines. It starts the week on Monday and ends on Sunday, matching international business calendars and many analytics tools.

For beginners, the key idea is simple: wrap any date expression in { $isoDayOfWeek: ... } inside a stage like $project or $group. Remember the numbering differs from $dayOfWeek, and results are based on UTC unless you use timezone-aware alternatives.

💡 Best Practices

✅ Do

  • Use $isoDayOfWeek for ISO 8601 / business-week reporting
  • Filter weekends with $in: [ { $isoDayOfWeek: ... }, [6, 7] ]
  • Pair with $isoWeek for full ISO calendar analysis
  • Document which weekday operator your team uses in dashboards
  • Use $dateToParts when a specific timezone matters

❌ Don’t

  • Mix $isoDayOfWeek filters with $dayOfWeek numbering
  • Assume Monday = 1 for both ISO and MongoDB default operators
  • Forget that extraction uses UTC by default
  • Use on string dates without converting to BSON Date first
  • Confuse weekday extraction with $dayOfMonth (day of month)

Key Takeaways

Knowledge Unlocked

Five things to remember about $isoDayOfWeek

Use these points when working with ISO weekdays in MongoDB.

5
Core concepts
📝 02

Simple Syntax

{ $isoDayOfWeek: date }

Syntax
🛠 03

Pipeline Stages

$project, $group, $match.

Usage
📈 04

Weekend Filter

Values 6 and 7.

Pattern
05

vs $dayOfWeek

Different numbering.

Important

❓ Frequently Asked Questions

$isoDayOfWeek returns an integer from 1 to 7 representing the ISO 8601 day of the week for a BSON Date. Monday is 1, Tuesday is 2, through Sunday which is 7.
The syntax is { $isoDayOfWeek: <dateExpression> }. Pass a field reference like "$orderDate", a literal ISODate, or another expression that evaluates to a date.
$isoDayOfWeek follows ISO 8601 (Monday=1, Sunday=7). $dayOfWeek uses MongoDB's default calendar (Sunday=1, Saturday=7). The same date can return different numbers.
$isoDayOfWeek extracts the weekday in UTC by default. For timezone-aware weekday extraction, use $dateToParts with a timezone option and read the isoDayOfWeek field.
$isoDayOfWeek returns null when the input date is null or refers to a missing field. It does not throw an error.

Continue the Operator Series

Move on to $isoWeek for ISO week numbers, or review $dayOfWeek for Sunday-based weekdays.

Next: $isoWeek →

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.

5 people found this page helpful