MongoDB $minute Operator

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

What Is $minute?

$minute is a MongoDB aggregation expression that returns the minute portion of a date as an integer from 0 to 59. For …T08:15:39.736Z, the result is 15.

Remember
$minute = minute part of a date (0 … 59)

{ $minute: <dateExpression> }

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

ISODate("…T08:15:39.736Z") → 15
ISODate("…T12:01:00Z") → 1

null / missing → null
string date → pipeline error
UsePrefer
Minutes (0–59)$minute
Hours (0–23)$hour
Seconds (0–59)$second

How to Use $minute in MongoDB

Pass a BSON date field (or expression), optionally with a timezone.

  1. Choose an expression stage ($addFields or $project).
  2. Pass a Date / Timestamp / ObjectId expression to $minute.
  3. Use the short form for UTC, or the document form with timezone for local minutes.
  4. Combine with $hour, $second, or $millisecond to break a timestamp into parts.
PieceRequired?Role
$minuteYesReturns minute 0–59
Date expressionYesDate, Timestamp, or ObjectId
timezoneNoOlson id or UTC offset (default: UTC)

Pseudocode

Pseudocode
for each document:
    d = evaluate(dateExpression)
    if d is null or missing:
        result = null
    else if d is a string:
        error  // aggregation fails
    else:
        result = minute part of d   // 0 … 59 (UTC or timezone)
    emit { ..., field: result }

Cheat Sheet

Keep these facts handy while extracting minutes.

TopicDetail
TypeAggregation expression (not a find filter)
Syntax{ $minute: <date> }
Range0 … 59
Input typesDate, Timestamp, ObjectId
Default zoneUTC
Sample…T08:15:39Z → 15
StringsNot allowed — convert first

Live Preview

Watch $minute pull the 0–59 part from a timestamp (UTC).

Simulates $minute in UTC (same idea as the mongosh examples below).

Result
date = 2014-01-01T08:15:39.736Z
$minute → 15

{ minutes: 15 }

Worked Walkthrough — Sale Timestamp

A sale was recorded at 2014-01-01T08:15:39.736Z. We want only the minute part.

Calculation
Document:
  { item: "abc", date: ISODate("2014-01-01T08:15:39.736Z") }

Break the time (UTC):
  hour   → 8
  minute → 15
  second → 39

$minute("$date") → 15

Check: clock shows 08:15 → minute is 15 ✓

MongoDB Examples

We use a small sales collection. First we extract minutes in UTC, then show the timezone form. Run these in mongosh after inserting the sample data once.

Example 1 — Sample Data

Imagine two sales with precise timestamps. We save them in a collection named sales.

mongosh
db.sales.insertMany([
  {
    _id: 1,
    item: "abc",
    price: 10,
    quantity: 2,
    date: ISODate("2014-01-01T08:15:39.736Z")
  },
  {
    _id: 2,
    item: "xyz",
    price: 20,
    quantity: 1,
    date: ISODate("2016-01-01T12:01:00.000Z")
  }
]);

How the Data Is Stored in MongoDB

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

mongosh
db.sales.find()

Read one document like this:

Field in MongoDBValue (doc 1)Plain English
_id1Document id
item"abc"Product code
date…T08:15:39.736ZSale time (BSON Date)

How It Works

  1. Insert once. insertMany adds two sale documents to sales.
  2. Dates are BSON Date. Use ISODate(...), not plain strings.
  3. find() shows the same shape. Ready for $minute next.

Example 2 — Extract Minutes

Goal: read the 0–59 minute portion of each sale’s date (UTC).

mongosh
db.sales.aggregate([
  {
    $addFields: {
      minutes: { $minute: "$date" }
    }
  }
]);

How It Works

  1. Read the stored date. Document 1 has …T08:15:39.736Z.
  2. Extract minutes. $minute: "$date" returns 15 (UTC).
  3. Second document. …T12:01:00Z → minute 1.
  4. Keep all fields. $addFields adds minutes next to the original sale data.

Example 3 — Minutes with Timezone

Same sales, but read the minute in a local offset. Offsets that include minutes (like +0530) can change the result.

mongosh
db.sales.aggregate([
  {
    $project: {
      item: 1,
      utcMinute: { $minute: "$date" },
      indiaMinute: {
        $minute: {
          date: "$date",
          timezone: "+0530"
        }
      }
    }
  }
]);

How It Works

  1. UTC first. Short form { $minute: "$date" } uses UTC → 15 and 1.
  2. Add +5:30. Document form with timezone: "+0530" shifts the clock by 5 hours 30 minutes.
  3. Minutes can change. 08:15 UTC → 13:45 IST, so indiaMinute is 45.
  4. Second row. 12:01 UTC → 17:31 IST → minute 31.

Edge Cases & Pitfalls

Check these before using $minute in production pipelines.

type

No string dates

Passing "2014-01-01" fails. Store BSON Date, or convert with $toDate / $dateFromString first.

null

Null and missing become null

Missing fields return null, not an error. Handle them before math if nulls are invalid in your data.

tz

Timezone can change the minute

Offsets like +0530 or zones such as Newfoundland shift minutes, not only hours. Always state whether you want UTC or local.

vs

Don’t confuse with $hour / $second

For …T08:15:39Z, hour is 8, minute is 15, second is 39. Use the operator that matches the part you need.

Performance Notes

ApproachCostBest for
$minute alonePer-document date mathNeed only the minute part
Several date partsStill O(docs)Hour / minute / second reports
+ timezoneSmall extra conversionLocal calendar views

Date-part expressions are cheap compared with large sorts or joins. Filter early with $match when only some documents need the minute value.

Key Takeaways

  • Role: date → minute 0–59.
  • Input: Date / Timestamp / ObjectId (not strings).
  • Sample: …T08:15:39Z → 15.
  • Timezone: offsets like +0530 can change minutes.

One line: $minute answers “what is the 0–59 minute part of this date?”—in aggregation.

Frequently Asked Questions

$minute returns an integer from 0 to 59 — the minute portion of a date within the current hour. For ISODate("…T08:15:39.736Z"), it returns 15. Use it inside aggregation expression stages such as $project and $addFields.
Short form: { $minute: <dateExpression> }. Document form: { $minute: { date: <dateExpression>, timezone: <tz> } }. The date must resolve to a Date, Timestamp, or ObjectId—not a string.
$hour returns 0–23, $minute returns 0–59, and $second returns 0–59. Together they describe clock time. $millisecond returns 0–999 for the fraction of the second.
Yes by default. Pass timezone (Olson id like "America/New_York" or an offset like "+0530") in the document form when you need the local minute.
$minute returns null when the input is null or the field is missing. A plain string date causes an aggregation error.
No. Strings like "2014-01-01" cause an error. Store BSON Date / ISODate, or convert first with $toDate / $dateFromString.

Next: $mod

Get the remainder after dividing two numbers in aggregation.

$mod 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