Home/IDs & Random/MongoDB ObjectId Generator

MongoDB ObjectId Generator

Create structurally valid MongoDB ObjectIds for any point in time, and decode the timestamp hidden inside any ObjectId you already have.

Free Browser-based No signup Copy-ready
Generator Settings
ObjectIds embed a one-second-resolution creation time, so this lets you build historical fixtures that sort correctly.
Real drivers keep this stable for the lifetime of a process. Fixing it makes a batch look like it came from one machine.
Increments per ID, wrapping at 16,777,215. Together with the timestamp this is what prevents collisions inside one process.
Options
Generated ObjectIds
objectids.txt

      
These are structurally valid ObjectIds for testing and fixtures. In production, always let the driver generate _id — it manages the per-process identifier and counter for you.

How it works

1

Set the timestamp

Now, a specific moment, or spread across a range for realistic historical data.

2

Generate a batch

The process bytes stay fixed and the counter increments, exactly as a real driver behaves.

3

Export or decode

Copy as shell syntax, Extended JSON or CSV — or paste an ObjectId to read its creation date.

What is actually inside an ObjectId

An ObjectId is 12 bytes, not a random string. It is built to be unique across machines without any coordination: a 4-byte second-resolution timestamp, 5 random bytes that stay constant for the lifetime of a process, and a 3-byte counter that increments with every document. Two processes would have to pick the same 5 random bytes and collide on the counter within the same second to produce a duplicate.

Practical consequences

  • sort({_id: -1}) gives you newest-first for free — no createdAt index required.
  • You can range-query by date against _id alone by constructing a boundary ObjectId.
  • Resolution is one second, so ordering within a single second reflects the counter, not real time.
  • The client generates _id, not the server, so inserts need no round trip to get an ID.

Things to be careful about

  • ObjectIds are not secrets. They expose creation time and are partially sequential, so they are guessable — never use one as an access token.
  • Passing a malformed 24-character string to the driver throws; validate user input first.
  • The old spec encoded machine ID and process ID, which leaked infrastructure detail. Modern drivers use random bytes instead.
  • The 32-bit timestamp overflows in 2106.
Generate ObjectIds here for fixtures, seed data and tests. In application code always call new ObjectId() from the driver — it owns the per-process random value and the counter state that make uniqueness guarantees hold.

Frequently Asked Questions

View all FAQs
How many characters are in a MongoDB ObjectId?
The standard hexadecimal representation is 24 characters, representing 12 bytes.
Does a MongoDB ObjectId contain a timestamp?
Yes. The first four bytes encode Unix time in seconds.
Can I extract the creation date from an ObjectId?
You can extract the timestamp encoded in the ObjectId. MongoDB also provides getTimestamp() for this purpose.
Is ObjectId globally unique?
Its timestamp, process-random value and counter are designed to make collisions extremely unlikely across clients. The _id field is also required to be unique within a collection.
Can I create an ObjectId for an old date?
Yes. That is useful for test fixtures and migration simulations. Use the timestamp controls above.
Should I generate production ObjectIds online?
Normally let your MongoDB driver generate production _id values. This tool is best for development, fixtures, examples and debugging.
Is this ObjectId generator free?
Yes. Generate and decode ObjectIds above without creating an account.

MongoDB ObjectId Generator & Decoder – Create Valid Test IDs Online

Need a realistic MongoDB _id for a fixture, seed file or query test? Use the MongoDB ObjectId Generator above to create structurally valid 12-byte ObjectIds without opening a shell or writing a helper script.

You can generate one ID or a batch, use the current time or choose a historical timestamp, keep one process identifier across the batch, control the starting counter and decode any existing 24-character ObjectId to inspect what is inside it.

The tool is intended for development, testing and debugging. In a production application, the safest normal practice is still to let your MongoDB driver generate ObjectIds because the driver manages the process-specific value and counter for you.

What Is a MongoDB ObjectId?

A MongoDB ObjectId is a 12-byte BSON value commonly used as the default value of the _id field.

When written as hexadecimal text, those 12 bytes become 24 characters.

Example:

507f1f77bcf86cd799439011

The modern ObjectId layout contains three parts:

PartSizePurpose
Timestamp4 bytesUnix time in seconds
Process random value5 bytesRandom value unique to a process
Counter3 bytesIncrementing value initialized randomly
Total12 bytesComplete ObjectId

The timestamp and counter bytes are stored most-significant-byte first.

How to Use This MongoDB ObjectId Generator

Choose how many ObjectIds you need.

For ordinary fixtures, keep the timestamp set to the current time. If you are building historical data, select a specific date and time.

Next, choose the process identifier.

Leaving it on automatic creates a random five-byte value for the batch. Keeping that value stable makes the generated set resemble IDs created by one running client process.

Set the counter start if you need predictable sequential values within the same timestamp.

Then choose the output format and generate the batch.

You can also paste an existing ObjectId into the decoder. The tool will break it into its timestamp, process-random and counter portions so you can see how the value was formed.

Why Is an ObjectId 24 Characters Long?

The underlying ObjectId is 12 bytes.

Each byte contains 8 bits, giving:

12 × 8 = 96 bits

Hexadecimal represents each byte with two characters.

So:

12 bytes × 2 hex characters = 24 characters

That is why a MongoDB ObjectId string is normally exactly 24 hexadecimal characters using digits 0–9 and letters a–f.

Uppercase hexadecimal can represent the same bytes, although MongoDB commonly displays ObjectIds in lowercase.

A random 24-character hex string may fit the textual length, but that alone does not make it a realistic driver-generated ObjectId. Real ObjectIds have a defined timestamp/process/counter structure.

The 4-Byte ObjectId Timestamp

The first four bytes encode a Unix timestamp in seconds.

That means an ObjectId usually reveals approximately when it was created.

MongoDB can retrieve this value with getTimestamp().

Because the timestamp resolution is one second, many ObjectIds created during the same second share the same first eight hexadecimal characters.

That does not create a collision by itself. The remaining five-byte process value and three-byte counter distinguish IDs created within that period.

The embedded timestamp is useful for debugging and rough sorting, but it should not replace an explicit business date field.

Decode an ObjectId to a Date

If you already have an ObjectId, paste it into the decoder.

The first eight hexadecimal characters represent the four-byte timestamp.

The decoder converts that value from Unix seconds into a human-readable date and time.

This is useful when investigating:

  • Old fixture data
  • Imported records
  • Log entries
  • API responses
  • Suspicious record order
  • Migration output
  • Example IDs in documentation

Remember that the decoded time tells you the timestamp encoded in the ID. It does not prove when a document was inserted into its current collection.

ObjectIds can be generated manually or moved between systems.

What Is the 5-Byte Process Random Value?

The middle five bytes are a random value generated for the client-side process.

MongoDB documentation describes this value as unique to the machine and process. It is generated again when the process restarts.

A normal driver keeps it stable while the process remains alive.

That is why this generator lets you keep one process value across a batch.

If you are creating 100 fixture IDs intended to look as though they came from one application process, one stable value produces a more realistic structure than choosing a new five-byte random block for every row.

For normal production writes, leave this job to the driver.

What Is the 3-Byte Counter?

The final three bytes form an incrementing counter.

Three bytes can represent:

2^24 = 16,777,216

different counter values before wrapping.

The counter is initialized to a random value when a process starts and increments for each ObjectId produced by that process.

Together with the timestamp and process value, it helps prevent IDs generated within the same second from colliding.

In a realistic fixture batch, incrementing the counter creates the same structural pattern you would expect from one process generating several IDs close together.

Are MongoDB ObjectIds Sorted by Creation Time?

ObjectIds are roughly sortable by creation time because the timestamp comes first.

However, “roughly” matters.

The timestamp only has one-second resolution. Several processes can create IDs during the same second, each with a different process-random value and counter state.

That means sorting ObjectIds is useful for broad chronology but should not be treated as a perfect global event sequence.

If exact ordering matters, store an explicit timestamp or sequence appropriate to your application.

For newer system designs where millisecond ordering and UUID compatibility are important, compare the UUID v7 Generator as well.

Generate an ObjectId for a Specific Timestamp

Historical ObjectIds are useful in tests.

Suppose you are testing a retention rule that affects documents older than 90 days. You may want fixtures whose IDs carry older timestamps so your test data resembles real MongoDB records.

Choose the required date in the generator and create the batch.

It is useful for pagination tests, time-range examples, migration rehearsals, seed databases and integration fixtures.

Do not create backdated production IDs merely to make a record appear older. Use explicit application fields for business dates.

ObjectId vs UUID v7

Both can work as distributed identifiers, but their structures differ.

FeatureObjectIdUUID v7
Binary size12 bytes16 bytes
Common text length2436
Timestamp resolutionSecondsMilliseconds
Time orderedRoughlyYes
Native MongoDB defaultYesNo
Standard UUID formatNoYes

Use ObjectId when MongoDB’s native conventions fit your application.

Use UUID v7 when identifiers need to move cleanly across systems that already understand UUIDs or when millisecond timestamp ordering is useful.

ObjectId vs ULID

ULID is another timestamp-first identifier.

A ULID is 128 bits and uses a 26-character Crockford Base32 representation. Its timestamp has millisecond resolution.

ObjectId is smaller at 96 bits and is deeply associated with MongoDB.

ULID is attractive when you want a sortable identifier that remains compact as text across different databases.

ObjectId is usually simpler when MongoDB itself is the center of the system.

Use the ULID Generator if you want to compare the text length, decoded timestamp and sorting behavior directly.

Should You Manually Generate Production _id Values?

Usually, no.

MongoDB drivers already know how to create ObjectIds correctly.

Manual generation is most useful when you need controlled fixtures, examples, migration data or debugging.

If you decide to supply your own production _id, uniqueness becomes your responsibility. MongoDB requires _id values to be unique within a collection, but your application must still generate a valid non-colliding value.

Do not copy a generated example from documentation into several real records.

Common MongoDB ObjectId Mistakes

Avoid these common assumptions:

  • Every 24-character string is a valid ObjectId
  • The timestamp has millisecond precision
  • ObjectId sorting provides perfect event order
  • The ObjectId creation time always equals database insertion time
  • A new random process block should be generated for every ID in one process
  • The counter can be ignored when imitating realistic batches
  • A hand-built production ID is automatically safe because it has the right length

Use the decoder when an unfamiliar ObjectId needs inspection rather than guessing from the string. For a broader entropy source, see the Random Hex String Generator, and see the NanoID Generator for compact alternatives.

Related searches

mongodb objectid generatorobjectid decoderobjectid timestampobjectid structure12 byte objectidobjectid vs uuid v7objectid vs ulidmongodb _id generatorgetTimestamp objectidobjectid test fixturesobjectid counter byteobjectid process random value