MongoDB ObjectId Decoder & Generator
Decode a MongoDB ObjectId to its creation date, random value and counter, make an ObjectId for a date (for _id range queries), or generate a new one.
Every MongoDB document gets an _id of type ObjectId: 12 bytes written as 24 hex digits. The first four bytes are the creation time in seconds, so an ObjectId tells you when a document was inserted, and ObjectIds sort roughly by time. This tool decodes an ObjectId into its date, random value and counter, builds the smallest ObjectId for a given date so you can query _id ranges, and generates new ObjectIds.
How to use this tool
- Choose decode, ObjectId for a date, or generate.
- Paste the ObjectId — plain hex or ObjectId("…") both work.
- For range queries, enter a date and time with a time zone (Z for UTC).
- Copy the date, the ObjectId or the ready-made shell query.
Formula
ObjectId = timestamp (4 bytes, seconds since 1970) ‖ random value (5 bytes) ‖ counter (3 bytes)
All parts are big-endian. The random value is generated once per process; the counter starts at a random value and increases by one for each new ObjectId. An ObjectId with the counter and random value set to zero is the smallest possible for that second, which makes it a lower bound in a query.
Example
The documentation example 507f1f77bcf86cd799439011 starts with 507f1f77 = 1,350,508,407 seconds, which is 2012-10-17 21:13:27 UTC; the random value is bcf86cd799 and the counter 0x439011 = 4,427,793. The ObjectId for 2026-01-01 00:00:00 UTC is 6955b9000000000000000000.
Frequently asked questions
Can I get the creation date in MongoDB itself?
Yes: ObjectId("…").getTimestamp() in mongosh returns the same date. This page is handy when you only have the ID, for example in a log line or URL.
Are ObjectIds secret or unguessable?
No. They reveal the creation time and the counter is sequential, so nearby IDs can be guessed. Do not use them as access tokens.
Why do my two ObjectIds have the same first 8 digits?
They were created in the same second. The counter (last 6 digits) still keeps them unique and ordered within one process.
Sources
Last updated:
Page address with these inputs: https://kakao.mobile/tools/objectid-decoder/
Cite or embed this tool
kakaoCalc. (2026, November 8). MongoDB ObjectId Decoder & Generator. https://kakao.mobile/tools/objectid-decoder/
“MongoDB ObjectId Decoder & Generator.” kakaoCalc, 8 Nov. 2026, kakao.mobile/tools/objectid-decoder/.
Paste this code into your page. The widget runs in your visitors' browsers, shows no ads and keeps a link back to this page. Embedding terms