MongoDB ObjectId generator — new IDs, any timestamp, and a decoder

Generate up to 1,000 MongoDB ObjectIds for the current time or a timestamp you choose, or paste an ObjectId to see the moment it was created.

Live demo · real result from this tool
Mode

Press Generate to create a result.

Processed on your device — nothing is uploaded.

How to use the ObjectId generator

  1. Leave Mode on Generate.
  2. Leave Timestamp (blank = now, UTC) empty for the current time, or pick a date and time. It is read as UTC.
  3. Set How many ObjectIds (up to 1,000) and press Generate.
  4. To read an ID, switch Mode to Read the timestamp, paste the ObjectId, and read Created (UTC) and Unix seconds.

What it does and when to use it

MongoDB gives every document an _id, and by default it is an ObjectId. Developers need them outside the database too: in JSON fixtures, seed scripts, mock API responses, and when writing references between collections by hand. This page makes IDs in the exact format, so drivers and validation accept them.

Setting the timestamp is the useful extra. Because the time sits at the front, ObjectIds sort roughly by creation time, and a hand-made ObjectId for a given moment works as a cut-off in queries. The decoder answers the common support question “when was this record created?” straight from the ID.

For time-sortable IDs outside MongoDB, see the ULID generator or version 7 in the UUID generator. To turn Unix seconds into a readable date in other formats, use the Unix timestamp converter.

How it works

The tool writes the chosen time as 8 hex digits of Unix seconds. It then draws a 5-byte random value and a random starting counter with crypto.getRandomValues, once per batch, which is how MongoDB drivers behave within one process. Each ID adds one to the counter, so a batch is in strict order. Decoding reads the first 8 hex digits back as seconds.

Worked examples

  • MongoDB’s documentation example. 507f1f77bcf86cd799439011 decodes to Created (UTC): 2012-10-17T21:13:27.000Z and Unix seconds: 1350508407.
  • Pasted from the shell. ObjectId("507f1f77bcf86cd799439011") gives the same answer.
  • A fixed start of year. Timestamp 2026-01-01 00:00 makes IDs that all begin 6955b900, for example 6955b900abb9973ea0695889 and 6955b900abb9973ea069588a. The last digits count up.
  • Not an ObjectId. xyz returns “An ObjectId is 24 hexadecimal characters.”

Limits and tips

  • Precision is one second. IDs made in the same second sort by counter, not by real order across machines.
  • The 4-byte time field runs out in the year 2106.
  • The tool does not check whether an ID already exists in your database.

Frequently asked questions

What is inside an ObjectId?
Twelve bytes, written as 24 hex characters. The first 4 bytes are the creation time in seconds since 1970 (UTC). The next 5 are a random value, the same for every ID one process makes. The last 3 are a counter that starts at a random number and goes up by one per ID.
Why would I want an ObjectId with a past or future time?
To build test data that spans months or years, to back-fill old records so they sort correctly, or to make boundary IDs for range queries. A query such as _id greater than the ObjectId for 2026-01-01 00:00 finds every document created since then.
Can I paste an ObjectId with the ObjectId(...) wrapper?
Yes. The decoder strips ObjectId(" ") from text copied out of the Mongo shell or Compass, and ignores upper or lower case.
Are ObjectIds secret or unguessable?
No. The time is readable by anyone, and IDs from one batch share the random part and differ only in the counter. Never use an ObjectId as a password-reset link or access token on its own.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close