MongoDB ObjectId to date converter
Paste the _id of a MongoDB document to see when it was created, without a createdAt field or running getTimestamp() in the shell.
Loading the tool…
Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.
How to use it
- Enter objectid and time zone (optional).
- The result appears straight away and updates as you edit.
- Copy the result, or copy a link that keeps the same values to share it.
How it is calculated
The first 4 bytes (8 hex digits) are a big-endian integer of Unix seconds since 1970-01-01 UTC. Bytes 5 to 9 are a random value and the last 3 bytes are a counter.
Example
Inputs: ObjectId = 507f1f77bcf86cd799439011, Time zone (optional) = Dubai (UAE). Result: Date and time (UTC): 2012-10-17 21:13:27; Weekday: Wednesday; Counter: 4,427,793.
507f1f77bcf86cd799439011
2012-10-17 21:13:27
Limits and caveats
- The time has one-second precision and comes from the clock of the machine or driver that made the ID, so it can be off if that clock was wrong.
- If the app set its own _id or used a type other than ObjectId, the value says nothing about creation time.
- In older IDs from before MongoDB 3.4, the middle bytes are a machine and process ID rather than a random value.
Questions about this tool
Does an ObjectId really hold the creation date?
Yes. Its first 8 hex digits are the seconds since 1970, which is why getTimestamp() in MongoDB returns the same date.
How do I find documents created after a certain date?
Take the lowest ObjectId for that second, shown in the results, and query { _id: { $gte: ObjectId("507f1f770000000000000000") } }.
Can I treat sorting by _id as sorting by time?
Only roughly. IDs made in the same second or on different machines may not be in exact creation order.
