1. Home
  2. Developer tools
  3. ObjectId Decoder

ObjectId Decoder

The first four bytes of a MongoDB ObjectId are the time it was created. Paste ObjectIds to see the date, the five random bytes and the counter, or build an id for a given date to query a range of _id values.

Free, no sign-up. Runs in your browser: nothing is uploaded.

How to use ObjectId Decoder

  1. Paste ObjectIds, one per line.
  2. Read the creation time, random part and counter.
  3. Or generate new ones or build one from a date.

Features

  • Decodes many ObjectIds at once
  • Creation time in UTC and as Unix seconds
  • Random 5-byte value and 3-byte counter
  • Generates new ObjectIds
  • Smallest ObjectId for any date
  • Accepts ObjectId("…") wrapped text

Supported formats

Input

  • ObjectId

You get

  • Date
  • Fields

Private by design

Everything you enter is processed by your browser on this device. Nothing is sent to openWorkstand or anyone else, so the ObjectId Decoder is safe for private and work data. After you have used it once while online, it also works without an internet connection. How local processing works

Good to know

  • The date is the moment the id was generated by the client or server, to the second.
  • The id says nothing about which database or collection holds the document.

Guide

Reading the creation time inside a MongoDB ObjectId

Every document in a MongoDB collection has an _id, and unless you supply your own it is an ObjectId: a compact 12-byte identifier that the driver creates before the document ever reaches the database. Because its first four bytes are a timestamp, an ObjectId doubles as a record of roughly when the document was made, which is handy for debugging and for date-range queries. This page splits an ObjectId into its parts and builds new ones.

The three parts

The 24 hexadecimal characters break down as follows. The first eight characters, four bytes, are the number of seconds since 1 January 1970 UTC, stored as a big-endian integer. The next ten characters, five bytes, are a random value generated once per process, which separates identifiers made by different machines or processes. The last six characters, three bytes, are a counter that starts at a random number and increases with each id the process creates.

Decoding

Paste ObjectIds one per line. The table lists each with its creation time in UTC, the Unix seconds, the random part and the counter as a number. The wrapper ObjectId(“…”) from the mongo shell is accepted, and uppercase digits are fine. A line that is not 24 hexadecimal characters gives a message with the reason, such as the wrong length. A column of Unix seconds is included because that number is what you would compare against other systems.

Generating and building ids

The “Generate a new ObjectId” button creates an id with the current time, your browser’s secure random bytes for the random part and a counter, and keeps the latest ten in a list. The date box builds the smallest ObjectId for a given moment: the eight time digits followed by sixteen zeros. Enter an ISO date such as 2024-01-15T09:30:00Z and copy the result. Dates before 1970 or after the year 2106 cannot fit the four bytes and are rejected.

Accuracy of the date

The time is the clock of the machine that generated the id, taken when the driver created it, usually the application server and not the database. If that clock was wrong, so is the date. It also shows when the id was made and not when the document was inserted, which can be later if the application held it back. Ids from a different generator, or custom _id values that only look like ObjectIds, decode into nonsense dates.

A worked example

The Sample button loads three ids. The first, 507f1f77bcf86cd799439011, is the example used in the MongoDB documentation. Its first eight digits, 507f1f77, are 1,350,508,407 seconds, which is 2012-10-17 21:13:27 UTC. The random part is bcf86cd799 and the counter is 439011, which is 4,427,793 in decimal. The second, 65a1b2c3d4e5f60718293a4b, decodes to 2024-01-12 21:44:35 UTC. Building the lowest id for 2024-01-15T09:30:00Z gives 65a4fb180000000000000000.

Limits

The random and counter parts do not carry meaning beyond uniqueness, and the page cannot tell which machine made an id. The generator here is for tests and examples; real applications should let the driver or the database create ids. Only the classic 12-byte structure is decoded, not other id types such as UUIDs or ULIDs, which have their own tools.

Checked against the current version of the ObjectId Decoder on .

Frequently asked questions

How do I query MongoDB for documents created after a certain date using only _id?

Build the ObjectId for that date on this page, then filter for an _id greater than or equal to it, for instance with ObjectId("65a4fb180000000000000000"). Because the time comes first, ids sort by creation second, and the zeros make it the lowest id for that moment.

Are two ObjectIds made in the same second always in creation order?

Not strictly. The first four bytes are equal, so the comparison falls to the random part, which is the same for one process, and then the counter. Within one process the counter increases, but across several processes the order inside a second is not guaranteed.

Can I trust the date in an ObjectId?

It is the time the id was generated, normally by the driver on the client, to the second. It is not a guarantee of when the document reached the database.

How do I query documents created after a date?

Build the ObjectId for that date here and query _id greater than or equal to it. Every document made from that second on has an _id at or above that value.

Keep working with the result

openWorkstand also includes a free workspace with documents, spreadsheets, tasks, projects and a calendar that save to a folder on your computer.