ObjectId decoder and generator from date
Paste an ObjectId, the 24-character ID that MongoDB puts in _id, to see when it was created and what its other parts hold. In the second box, enter a date to get the smallest ObjectId of that second, ready for a query that finds documents created after it.
Runs in your browser: nothing you enter is sent anywhere.
How to use it
- Paste an ObjectId into the first box. The creation time, Unix seconds, random value and counter appear below it.
- To go the other way, type a date in the second box: you get an ObjectId and a ready query for _id.
- Copy what you need with the copy buttons.
How it works
The first 8 hex digits are the creation time in seconds since 1970-01-01 UTC, big-endian. The next 10 digits are the per-process random value, and the last 6 are the counter.
For a date, the tool takes its Unix seconds (fractions dropped), writes them as 8 hex digits and adds 16 zeros. No real ID made in that second is smaller, which is why it works as a range boundary.
Worked example
507f1f77bcf86cd799439011:
- 507f1f77 in decimal is 1,350,508,407 seconds, which is 2012-10-17T21:13:27Z;
- bcf86cd799 is the random value;
- 439011 is the counter: 4,427,793 in decimal.
The other way, 2026-01-01T00:00:00Z is 1,767,225,600 seconds = 6955b900 in hex, so its ObjectId is 6955b9000000000000000000.
Tips
- Sorting by _id is roughly sorting by creation time, but only to the second; IDs from different processes in the same second are not ordered by time.
- To decode many IDs in code:
ObjectId("…").getTimestamp() in mongosh.
- For UUIDs use the UUID decoder; for Twitter or Discord IDs, the Snowflake ID decoder.
Frequently asked questions
What is inside an ObjectId?
12 bytes, written as 24 hex digits: 4 bytes of Unix time in seconds, 5 bytes of a random value chosen once per process, and a 3-byte counter that starts at a random number and grows by one with each new ID.
Is the creation time exact?
To the second, by the clock of the machine or driver that made the ID. Usually the client driver makes the ObjectId, so it is the client's clock, not the database server's.
How do I find documents created after a date?
Use the ObjectId of that date as a lower bound: db.orders.find({ _id: { $gte: ObjectId("…") } }). Because the time comes first, ObjectIds sort by creation second, and the generated ID (the time followed by 16 zeros) is the smallest one of that second.
Can I get the machine or process from an ObjectId?
Not any more. Older versions of the format held a machine and process ID; the current one uses a random 5-byte value per process, so it only tells you whether two IDs probably came from the same process.
Can I paste ObjectId("…")?
Yes, the ObjectId("…") wrapper from the shell is removed, and case does not matter.