MongoDB ObjectId Decoder & Generator
Read ObjectId creation times, inspect opaque random bytes and counters, generate test IDs, and build second-based query boundaries.
The 12-byte format
Modern BSON ObjectIds contain a 4-byte unsigned big-endian Unix-seconds timestamp, 5 opaque random bytes and a 3-byte counter. The middle bytes are not a reliable machine name or process ID. The timestamp ranges from 1970-01-01 to 2106-02-07T06:28:15Z and has second precision.
Parse, generate and compose
Decode accepts exactly 24 hexadecimal characters or an ObjectId("…") shell wrapper, up to 1,000 lines. Generation uses Web Crypto for a fresh 5-byte batch random value and a random initial counter, then increments the counter within the batch. Composition lets you specify the random bytes and counter for reproducible fixtures.
Query boundaries are not unique IDs
Boundary mode fixes the first four bytes to the selected second and returns the all-zero and all-FF suffixes. Use them as inclusive lower and upper bounds for that second, not as new document IDs. Fractional milliseconds are floored to seconds. Neither an ObjectId nor its timestamp proves ownership or the actual creation time of a record.
Questions & answers
Does a decoded time prove when a record was created?
The first four ObjectId bytes hold Unix seconds. An ID can be generated before insertion or composed manually, so check database records if you need the actual insertion time.
Are inputs uploaded or saved?
No. The tool runs locally in a Web Worker and does not send IDs to an API or save them in local storage. Copy and Download use the current result; edits or cancellation discard stale output.
Other Languages
References
How we make sure
We check this tool with the automated test suites linked below. Example checks are shown in their original language.
- Verification method
- Check encoded fields, integer precision, alphabets and boundaries using fixed IDs/timestamps, plus applicable monotonic generation.
- Comparison reference
- Fixed field/timestamp fixtures for each format; Snowflake includes a published Discord vector.
- Verification scope
- Field and finite-sample checks do not guarantee collision-free random IDs.
Test source and cases (select a file to read it)
-
identifier-tools.test.js
- Discord documented Snowflake vector and exact composition
- Snowflake all bit fields preserve integers above 2^53 and full uint64 Discord range
These checks cover the listed examples and boundaries, not every possible input. Round trips and checks using the same library are not independent verification.