MongoDB $minute Operator

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

What You’ll Learn

The $minute operator extracts the minute portion (0–59) from a BSON Date inside MongoDB aggregation pipelines. Use it for scheduling analysis, cron-style patterns, per-minute dashboards, and time-slot reporting.

01

Extract Minute

Date → 0–59.

02

Syntax

One date argument.

03

Timezone Option

Local minute support.

04

UTC Default

0–59 in UTC.

05

Use Cases

Slots, cron jobs.

06

Related Ops

$hour, $second.

Definition and Usage

In MongoDB’s aggregation framework, the $minute operator takes a date expression and returns an integer between 0 and 59. For example, $minute applied to ISODate("2024-06-15T14:30:45Z") returns 30, and ISODate("2024-06-15T09:05:00Z") returns 5.

Minutes sit between $hour and $second in MongoDB’s date-extraction family. Together they let you break any timestamp into readable parts for filtering, grouping, or display.

💡
Beginner Tip

$minute uses UTC by default. For appointment slots or business rules in local time, use the object form with a timezone option (see Example 4).

📝 Syntax

The $minute operator takes a date expression, or an object with date and timezone:

mongosh
{ $minute: <dateExpression> }

// With timezone:
{
  $minute: {
    date: <dateExpression>,
    timezone: <tz>
  }
}

Syntax Rules

  • Argument — any expression that evaluates to a BSON Date (field, $$NOW, or literal).
  • Return value — integer from 0 to 59 (minute within the hour).
  • Null input — returns null when the date is null or missing.
  • Timezone — optional; use Olson timezone IDs like "America/New_York".
  • Use inside $project, $addFields, $set, $match (with $expr), or $group.

💡 $minute vs $hour vs $dateTrunc

14:30:45Z$hour: 14, $minute: 30, $second: 45
$minute — BSON Date → integer 0–59 (minute component)
$dateTrunc — BSON Date → Date at period boundary (great for hourly buckets)

⚡ Quick Reference

QuestionAnswer
Operator typeAggregation expression operator (date extraction)
ArgumentsOne date expression
Return typeInteger (0–59)
Timezone supportYes (object form with timezone)
MongoDB version3.4+
From field
{ $minute: "$scheduledAt" }

Minute component

2:30 PM UTC
{ $minute: ISODate("2024-06-15T14:30:00Z") }

Returns 30

In $project
{
  minute: { $minute: "$eventAt" }
}

Add computed field

With timezone
{
  $minute: {
    date: "$eventAt",
    timezone: "America/New_York"
  }
}

Local minute

Examples Gallery

Extract minute values, find top-of-hour events, group activity by minute of the hour, and read minutes in a local timezone.

📚 Appointment Scheduling

Use an appointments collection and extract minutes from scheduledAt.

Sample Input Documents

Suppose you have an appointments collection with scheduled times:

mongosh
[
  {
    "_id": ObjectId("609c26812e9274a86871bc6a"),
    "patient": "Alice",
    "scheduledAt": ISODate("2024-06-15T09:30:00Z")
  },
  {
    "_id": ObjectId("609c26812e9274a86871bc6b"),
    "patient": "Bob",
    "scheduledAt": ISODate("2024-06-15T14:05:00Z")
  },
  {
    "_id": ObjectId("609c26812e9274a86871bc6c"),
    "patient": "Carol",
    "scheduledAt": ISODate("2024-06-15T10:00:00Z")
  }
]

Example 1 — Add minute with $minute

Extract the minute component from each appointment time:

mongosh
db.appointments.aggregate([
  {
    $project: {
      patient: 1,
      scheduledAt: 1,
      minute: { $minute: "$scheduledAt" }
    }
  }
])

How It Works

  • 09:30 UTC → minute 30.
  • 14:05 UTC → minute 5.
  • 10:00 UTC → minute 0 (top of the hour).

📈 Practical Patterns

Cron-style filters, per-minute grouping, and timezone-aware extraction.

Example 2 — Find Appointments at the Top of the Hour

Match records scheduled exactly on the hour (minute == 0):

mongosh
db.appointments.find({
  $expr: {
    $eq: [
      { $minute: "$scheduledAt" },
      0
    ]
  }
})

How It Works

Combine $minute with $eq inside $expr. This pattern is useful for cron jobs, hourly batch tasks, or events that always fire on the hour.

Example 3 — Group Events by Minute of the Hour

See which minute slots within each hour are busiest across all days:

mongosh
db.appointments.aggregate([
  {
    $group: {
      _id: { $minute: "$scheduledAt" },
      count: { $sum: 1 }
    }
  },
  { $sort: { "_id": 1 } }
])

How It Works

Grouping by $minute aggregates all hours and days together — useful for spotting patterns like “most bookings happen at :00 or :30.” Pair with $hour if you need hour-and-minute combinations.

Example 4 — Minute in a Specific Timezone

Extract the minute in Eastern Time rather than UTC:

mongosh
db.appointments.aggregate([
  {
    $project: {
      patient: 1,
      scheduledAt: 1,
      minuteUtc: { $minute: "$scheduledAt" },
      minuteEastern: {
        $minute: {
          date: "$scheduledAt",
          timezone: "America/New_York"
        }
      }
    }
  }
])

// scheduledAt: 2024-06-15T14:30:00Z
// minuteUtc: 30, minuteEastern: 30 (EDT, same in this case)

How It Works

The object form with timezone converts the instant to the specified zone before extracting the minute. UTC and local values can differ when the local hour boundary does not align with UTC.

Bonus — Hour and Minute Time Slot

Build a readable time slot label from hour and minute:

mongosh
db.appointments.aggregate([
  {
    $project: {
      patient: 1,
      scheduledAt: 1,
      timeSlot: {
        $concat: [
          { $toString: { $hour: "$scheduledAt" } },
          ":",
          {
            $cond: {
              if: { $lt: [ { $minute: "$scheduledAt" }, 10 ] },
              then: {
                $concat: [
                  "0",
                  { $toString: { $minute: "$scheduledAt" } }
                ]
              },
              else: { $toString: { $minute: "$scheduledAt" } }
            }
          }
        ]
      }
    }
  }
])

How It Works

Combine $hour and $minute with $concat and $cond to pad single-digit minutes. For 09:05 UTC, the slot label becomes "9:05".

🚀 Use Cases

  • Scheduling slots — group or filter appointments by minute within the hour.
  • Cron-style analysis — find jobs that run at :00, :15, :30, or :45.
  • Traffic patterns — discover which minute marks see the most activity.
  • Time-slot labels — combine with $hour for readable display values.

🧠 How $minute Works

1

MongoDB resolves the date

The input expression is evaluated per document — a field, $$NOW, or literal ISODate.

Input
2

$minute extracts the minute

MongoDB reads the minute component as an integer 0–59 (UTC or specified timezone).

Extract
3

An integer is returned

The number is ready for $match, $group, or time-slot logic.

Output
=

Minute for scheduling analytics

Combine with $hour, $second, and $dateTrunc for richer time reporting.

Conclusion

The $minute operator is a simple way to extract the minute component from BSON dates in MongoDB aggregation pipelines. It is especially useful for scheduling analysis, cron-style filters, and per-minute dashboards.

Remember it uses UTC by default and returns 0–59. For local business rules, pass a timezone in the object form. Next in the series: $mod.

💡 Best Practices

✅ Do

  • Use $minute for minute-within-hour extraction (0–59)
  • Combine with $hour for full time-slot labels
  • Pass timezone when scheduling rules follow local time
  • Use $dateTrunc when you need minute-level buckets as Dates
  • Store dates as BSON Date type for reliable extraction

❌ Don’t

  • Confuse $minute with total minutes since midnight (compute that separately)
  • Use it on string dates without converting to Date first
  • Assume minute values carry hour context (they reset each hour)
  • Forget UTC default when comparing to local appointment times
  • Use $minute when $dateTrunc with unit: "minute" fits better

Key Takeaways

Knowledge Unlocked

Five things to remember about $minute

Use these points when working with minute-level date extraction in MongoDB.

5
Core concepts
📝 02

One Date Arg

Field or ISODate.

Syntax
🛠 03

UTC Default

Timezone optional.

Timezone
🔄 04

Resets Each Hour

Not cumulative.

Edge case
📑 05

Date Family

$hour, $second.

Related

❓ Frequently Asked Questions

$minute returns an integer from 0 to 59 representing the minute portion of a BSON Date. For example, 2:30 PM UTC returns 30, and 9:05 AM UTC returns 5.
Simple form: { $minute: <dateExpression> }. With timezone: { $minute: { date: <dateExpression>, timezone: <tz> } }. Pass a field like "$scheduledAt" or a literal ISODate.
By default, $minute uses UTC. To get the minute in a specific timezone, use the object form with a timezone string like "America/New_York".
$minute returns 0–59 (minute within the hour). $hour returns 0–23. $dateTrunc rounds a Date down to a period boundary — better for bucketing than extracting a single component.
$minute is available in MongoDB 3.4 and later in aggregation pipelines and update pipelines that use aggregation expressions.

Continue the Operator Series

Move on to $mod for modulo arithmetic, or review $hour for hour-of-day analysis.

Next: $mod →

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