MongoDB ObjectId Inspector
Paste a 24-character MongoDB ObjectId to unpack the creation time stored in its first 4 bytes, the 5-byte random value and the 3-byte counter. You can also turn any date into the earliest possible ObjectId for that second, ready for _id range queries. Everything runs locally in your browser.
How to use
- Paste an ObjectId into the input, or click Load example. Wrapped forms such as ObjectId("…"), a quoted string or {"$oid": "…"} are accepted.
- Read when it was created (relative, local time and ISO 8601 in UTC) and the Timestamp, Random and Counter fields; each has a Copy button.
- To build an ObjectId from a date, pick a date and time under Build an ObjectId from a date, or click Now.
- Copy the ObjectId at that time, or click Decode above to inspect it.
Example
Input
ObjectId("507f1f77bcf86cd799439011")Output
Local time: 10/17/2012, 9:13:27 PM (here in UTC)
ISO 8601 (UTC): 2012-10-17T21:13:27.000Z
Timestamp (4 bytes): 1350508407
Random (5 bytes): bcf86cd799
Counter (3 bytes): 439011 (4427793)Frequently asked questions
How precise is the creation time?
To the second. The first 4 bytes hold the Unix time in seconds when the ObjectId was generated, usually by the driver on the client, so it reflects that machine's clock rather than when the document was written.
How do I find documents created after a certain date?
Enter the date under Build an ObjectId from a date and copy the result. Its timestamp bytes match that instant and the other 8 bytes are zero, so it is the lowest ObjectId for that second; use it in a query such as {_id: {$gte: ObjectId("…")}}. The date is interpreted in your local time zone.
What are the random value and the counter?
The 5-byte random value is generated once per process when the driver starts, and the 3-byte counter starts at a random value and increases with each new ObjectId. The counter is shown in hex and, in brackets, as a decimal number.
Why is my ObjectId rejected?
After unwrapping, the value must be exactly 24 hexadecimal characters (0–9, a–f). Values that are too short or long, or that contain other characters, show the Not a valid ObjectId message.