MongoDB ObjectId Decoder
Decode a MongoDB ObjectId into its creation time, process random value and counter, or generate new ObjectIds in your browser.
Free · No sign-up · Your inputs stay in your browser
Input
Decode or generate a MongoDB ObjectId
Output
2024-03-13T12:57:23.000Z
| Created (UTC) | 2024-03-13T12:57:23.000Z |
|---|---|
| Unix seconds | 1710334643 |
| Process random | c4d5e6f708 |
| Counter | 1649211 |
| Find by time | db.items.find({ _id: { $gte: ObjectId("65f1a2b30000000000000000") } }) |
An ObjectId is 4 bytes of seconds since the Unix epoch, 5 random bytes chosen once per process, and a 3-byte counter. The timestamp is when the id was generated by the driver, not when the document was written, and it has one-second resolution. Range-querying _id by time works because the timestamp comes first.
Runs in this browser. Nothing you paste is sent to a server.
About this tool
Method, assumptions, practical next steps, and limits.
A free created_at, with limits
Because the timestamp comes first, ObjectIds sort roughly by creation time and ObjectId.getTimestamp() gives a creation date without a separate field. The time is when the driver generated the id, which is usually but not always when the document was inserted, and it has one-second resolution. See the ObjectId reference.
Not a secret
Anyone who sees an ObjectId can read when it was created, and ids generated close together are predictable. Do not use them as unguessable tokens in URLs for private resources.