MongoDB ObjectId Generator & Decoder
NewGenerate a valid MongoDB ObjectId or decode an existing one to reveal its embedded creation timestamp, random value, and counter.
—
A MongoDB ObjectId is 12 bytes (24 hex characters): a 4-byte Unix timestamp (seconds), a 5-byte random value (unique per machine+process), and a 3-byte incrementing counter. This means every ObjectId embeds its own creation time, which is why ObjectIds sort roughly in creation order.
Frequently Asked Questions
What exactly is inside a MongoDB ObjectId?
It is 12 bytes total: a 4-byte Unix timestamp (seconds since epoch), a 5-byte random value unique to the generating machine and process, and a 3-byte incrementing counter — represented together as a 24-character hex string.
Can I get the creation date of a document just from its _id?
Yes, as long as it uses the default ObjectId type: the first 4 bytes are a Unix timestamp in seconds, so decoding any ObjectId reveals exactly when it was generated, down to the second.
Are ObjectIds guaranteed to be globally unique?
They are effectively unique in practice because they combine a timestamp, a random per-machine/process value, and an incrementing counter, but unlike a cryptographic UUID they are not collision-proof by mathematical guarantee — just extremely unlikely to collide.
Do ObjectIds generated by this tool work in a real MongoDB database?
Yes, the generator follows MongoDB's exact 12-byte ObjectId specification, so the generated hex string is a structurally valid ObjectId you can insert as an _id value.
Why do ObjectIds sort in roughly chronological order?
Because the first 4 bytes are a timestamp and hex string comparison is effectively byte-by-byte, sorting ObjectIds as strings or via MongoDB's default _id index closely (though not perfectly, due to the random/counter suffix) tracks their creation order.