Embed this tool on your site
About this tool
The MongoDB ObjectId Generator creates ObjectIds in MongoDB's 24-character hex format and decodes existing ObjectIds to show when they were created. A MongoDB ObjectId is a 12-byte value: 4 bytes for a Unix timestamp (second precision), 5 random bytes, and 3 bytes of incrementing counter. ObjectIds are the default _id type in MongoDB collections and are designed to be unique across machines and time without central coordination. Here the Count slider makes 1 to 50 ObjectIds per click from the current time, each listed with its UTC creation time and a Copy button, plus Copy All. The tool draws fresh random bytes for every ID rather than once per process as drivers do, which still yields valid ObjectIds. Paste any 24-character hex string into the Decode ObjectID box to see its creation time in UTC and as Unix epoch seconds; the random and counter bytes are not broken out.
Why use it
Generates spec-compliant MongoDB ObjectIds without requiring a MongoDB connection.
Decodes ObjectIds to reveal the embedded creation timestamp.
Useful for debugging, testing, and seeding MongoDB databases.
Runs entirely in the browser — no driver or database needed.
Half the size of a UUID v4 hex (24 vs 32 chars) while still embedding a useful timestamp prefix.
Default _id type in every MongoDB collection — using ObjectId keeps your schema idiomatic and your indexes compact.
How to use
- Move the Count slider (1-50) to choose how many ObjectIds to create; five are generated when the page loads.
- Click Generate to create a new batch at the current time. Each ID is listed with its UTC creation time.
- Click Copy next to an ID to copy the hex string, or Copy All for the full batch, one per line.
- Paste an existing 24-character ObjectId into the Decode ObjectID box to see its creation time in UTC and its epoch seconds, without writing a Mongo shell command.
When it helps
- Generating test ObjectIds for MongoDB database seeding or unit tests.
- Decoding an ObjectId from a database record to find its creation time.
- Creating ObjectIds for mock data fixtures in development.
- Learning the internal structure of MongoDB's BSON ObjectId format.
- Reverse-engineering the creation timestamp of legacy MongoDB documents that lack an explicit createdAt field.
Examples
01Generate at current time
InputCount: 1, click Generate
Expected result65b3c2f1a8d9e4f1a2b3c4d5 (listed with 2024-01-26 14:34:25 when generated at that second)
02Decode an existing ObjectId
Input5f4e1c9d8b7a6f5e4d3c2b1a
Expected resultCreated: 2020-09-01T10:04:13.000Z (epoch: 1598954653)
03Decode the MongoDB docs sample
Input507f1f77bcf86cd799439011
Expected resultCreated: 2012-10-17T21:13:27.000Z (epoch: 1350508407)
Expected resultObjectID must be 24 hex characters
Tips
- Treat ObjectIds as opaque 12-byte values in application code; do not slice the hex to extract the timestamp manually because the byte ordering is big-endian and easy to get wrong.
- MongoDB's ObjectId only encodes seconds, not milliseconds. Two ObjectIds from the same second sort by the bytes after the timestamp, not by sub-second time, so use a separate created_at field for fine-grained ordering.
- When inserting a custom ObjectId, validate that the 24-character hex string is exactly 24 chars and matches /^[0-9a-f]{24}$/i — most driver bugs come from accidentally passing short or uppercase strings.
- ObjectIds are not random: two IDs minted in the same second on the same process are predictable. Do not use them where unguessability matters, such as URL slugs for sensitive resources.
- If you migrate from MongoDB to a SQL store, store ObjectIds as BINARY(12) or BYTEA to keep index density tight and primary-key comparisons cheap.
- Avoid generating ObjectIds on the client unless the client is trusted; a malicious client could submit ObjectIds with future timestamps to manipulate sort order.
Frequently Asked Questions
What is a MongoDB ObjectId?⌄
An ObjectId is a 12-byte BSON type used as the default primary key in MongoDB. Current drivers build it from a 4-byte Unix timestamp, 5 random bytes and a 3-byte counter; older drivers used machine and process IDs in place of the random bytes.
How do I find when a document was created from its ObjectId?⌄
Paste the ObjectId into the Decode ObjectID box. The tool reads the 4-byte timestamp component and shows it as a UTC date and time plus Unix epoch seconds.
Are the generated ObjectIds compatible with real MongoDB?⌄
Yes. Each ID has the standard layout of 4 timestamp bytes, 5 random bytes and a 3-byte counter written as 24 lowercase hex characters, which any MongoDB driver accepts. The tool draws new random bytes for every ID instead of once per process, which does not affect validity.
What is the difference between ObjectId and UUID?⌄
ObjectId is 12 bytes (24 hex chars) and embeds a Unix timestamp. UUID is 16 bytes (36 chars with dashes) and is typically fully random (v4) or time-based (v1/v7).
Can I generate multiple ObjectIds at once?⌄
Yes. Set the Count slider anywhere from 1 to 50 and click Generate; Copy All copies the whole list.
Can I create an ObjectId for a past or future date?⌄
No. Generated IDs always use the current time. If you need a fixed timestamp, use ObjectId.createFromTime() in mongosh or your driver.
Can ObjectIds collide?⌄
Collision is theoretically possible but astronomically unlikely. With 5 random bytes and a 24-bit counter, you would need millions of IDs in one second from the same generator to hit a counter rollover.
What happens at the year-2106 timestamp rollover?⌄
The 32-bit timestamp wraps in February 2106. MongoDB has not yet announced an extended ObjectId format, but applications storing data past 2106 will need migration.
Glossary
- ObjectId
- MongoDB's default _id type — a 12-byte BSON value composed of a 4-byte timestamp, 5 random bytes, and a 3-byte counter, displayed as a 24-character hex string.
- BSON
- Binary JSON, MongoDB's storage and wire format. ObjectIds are a native BSON type, more compact than the equivalent UUID hex string.
- Timestamp bytes
- The first 4 bytes of an ObjectId, encoding seconds since the Unix epoch in big-endian byte order. Has rolled over considerations near year 2106.
- Random / machine bytes
- The middle 5 bytes of an ObjectId. Modern MongoDB drivers (3.4+) draw these from a cryptographic RNG once per process to identify the generator.
- Counter / sequence bytes
- The trailing 3 bytes of an ObjectId, an incrementing 24-bit counter that disambiguates IDs minted in the same second by the same process.
- BSON 24-char hex
- The standard human-readable representation of an ObjectId — exactly 24 lowercase hex characters with no separators or prefix.
- Process ID
- Older MongoDB driver versions split the random bytes into machine ID + process ID; modern drivers merged them into a single random field for security.
A LITTLE HELP. A LOT DONE.
Good tools.
Great flow.
Your shortcut to the everyday. Create, convert, calculate,
and get back to what you love.
✳
✳
✓ Free to use✓ No sign-up✓ 500+ possibilities