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
About this tool
The MongoDB ObjectId Generator creates valid BSON ObjectIds compatible with MongoDB and decodes existing ObjectIds to reveal their internal structure. A MongoDB ObjectId is a 12-byte value: 4 bytes for a Unix timestamp (second precision), 5 bytes of random machine/process data, 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. This tool lets you generate fresh ObjectIds, inspect the creation time encoded in any ObjectId, and convert between hex and binary representations.
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
- Click Generate to create a new MongoDB ObjectId.
- Use the Decode tab to paste an existing ObjectId and see its components.
- The creation timestamp is automatically extracted and shown in UTC.
- Click Copy to copy the ObjectId hex string.
- Use the Custom Timestamp field to mint an ObjectId for a chosen date — common when backfilling historical records or creating reproducible fixtures.
- Click Decode on any 24-character hex string to inspect its timestamp, random bytes, and counter 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.
- Generating reproducible fixtures for integration tests where ObjectIds need to be deterministic across runs.
Examples
01Generate at current time
Expected result65b3c2f1a8d9e4f1a2b3c4d5
02Decode an existing ObjectId
Input5f4e1c9d8b7a6f5e4d3c2b1a
Expected resultTimestamp: 2020-09-01T16:30:21.000Z
Random: 8b7a6f5e4d
Counter: 3c2b1a
03Generate at a historical date
InputTimestamp: 2020-01-01T00:00:00Z
Expected result5e0be100a1b2c3d4e5f60718
04Bulk generate 3 IDs in same second
Expected result65b3c2f1a8d9e4f1a2b3c4d5
65b3c2f1a8d9e4f1a2b3c4d6
65b3c2f1a8d9e4f1a2b3c4d7
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 counter, 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.
- When seeding test data, generate ObjectIds with controlled timestamps so your fixtures sort deterministically across test runs.
Frequently Asked Questions
What is a MongoDB ObjectId?⌄
An ObjectId is a 12-byte BSON type used as the default primary key in MongoDB. It encodes a Unix timestamp, machine identifier, process ID, and a random counter.
How do I find when a document was created from its ObjectId?⌄
Paste the ObjectId into the Decode tab. The tool extracts the 4-byte timestamp component and converts it to a UTC date and time.
Are the generated ObjectIds compatible with real MongoDB?⌄
Yes. The generator follows the BSON ObjectId specification and produces IDs that are fully compatible with MongoDB.
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 a count and the tool will generate and list multiple ObjectIds in one operation.
Are ObjectIds unique across collections?⌄
Yes — they are designed to be globally unique across collections, databases, and even MongoDB clusters, thanks to the random and counter bytes.
Can ObjectIds collide?⌄
Collision is theoretically possible but astronomically unlikely. With the modern 5-byte random per process and 24-bit counter, you would need millions of IDs in one second from the same process 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.