Inside an ObjectId
An ObjectId is 12 bytes, written as 24 hex digits: a 4-byte timestamp (seconds since 1970, so it sorts roughly by creation time), 5 random bytes chosen once per process, and a 3-byte counter that starts at a random value. That's why _ids from one server count up by one.
The timestamp has one-second precision and comes from the clock of whatever created the document, usually the application's driver, not the database server.
How to use the MongoDB ObjectId Decoder
- Paste ObjectIds, one per line, or press Sample.
- Read the creation time in UTC and your time zone.
- To query by date, enter a start date (and optionally an end date) and copy the query.
Examples
The ObjectId from MongoDB's documentation
507f1f77bcf86cd7994390112012-10-17T21:13:27.000ZShell syntax is accepted
ObjectId("507f191e810c19729de860ea")2012-10-17T20:46:22.000ZA query for November 2026
from: 2026-11-01T00:00:00Z
to: 2026-12-01T00:00:00Z{ _id: { $gte: ObjectId("6ae681000000000000000000"), $lt: ObjectId("6b0e0e000000000000000000") } }Documents created during November 2026, in UTC, using the _id index.
Querying by creation date
Every collection has an index on _id, so filtering by an ObjectId range is fast even without a createdAt field. An ObjectId whose remaining 8 bytes are zero is the smallest possible for its second, so { _id: { $gte: ObjectId("<that id>") } } finds everything created from that moment on.
Limitations
- Times have one-second precision and reflect the clock of the machine that created the ObjectId.
- Applications can set
_idthemselves: a custom ObjectId's timestamp may not be its real creation time.
Frequently asked questions
Is my data uploaded?
No. ObjectIds are decoded in your browser; nothing you paste is sent anywhere.
How do I get the timestamp in code?
In mongosh, ObjectId("…").getTimestamp(). In Node.js, new ObjectId(id).getTimestamp(). In JavaScript without a driver, new Date(parseInt(id.slice(0, 8), 16) * 1000).
Are ObjectIds unique?
In practice, yes: the timestamp, the per-process random value and the counter make collisions extremely unlikely. They're not secret, though: anyone can read the creation time.