MongoDB ObjectId Generator
Generate valid 24-hex MongoDB ObjectIds and decode any ObjectId to its embedded timestamp and BSON structure — entirely on this device.
Decoded fields
- Timestamp
- —
- Unix time (ms)
- —
- Random
- —
- Counter
- —
- Counter (hex)
- —
Decode an ObjectId
- Canonical (lowercase)
- —
12-byte structure
- Timestamp
- —
- Unix time (ms)
- —
- Random
- —
- Counter
- —
- Counter (hex)
- —
The timestamp has one-second precision — ObjectIds created in the same second sort by their counter, not their time.
Any 24-hex value decodes to a timestamp — a successful decode does not prove this value came from MongoDB.
Press ? for shortcuts
Do it offline:$ mongosh --quiet --eval 'ObjectId().toHexString()'
How to use it
- Set a count up to 10,000 and press Generate; one ObjectId is ready on load.
- Read the Decoded fields strip below: the first id's timestamp, random and counter.
- Paste an ObjectId, bare or wrapped as ObjectId("…"), to decode it live.
- Copy one value or the batch, or download .txt, .csv or .json.
A valid MongoDB ObjectId is on screen when this page loads — built in your browser, never fetched. Ask for one or a batch; the first value's 12 bytes are decoded right below. Paste any ObjectId to read its embedded second and counter.
How it works
An ObjectId is 12 bytes as 24 hex: 4 big-endian bytes of whole seconds, 5 random bytes, then a 3-byte counter. Time leads, so ids trend in creation order.
Generation keeps one random 5-byte value per session and bumps the counter per id, so a same-second batch still sorts. No database is contacted.
Examples
count = 1 · minted 2026-08-09T12:00:00Z6a786bc0a1b2c3d4e57fa5c2A freshly generated ObjectId; its random seed is pinned so this value reproduces.
507f1f77bcf86cd799439011timestamp = 2012-10-17T21:13:27.000Z (1350508407000 ms)
random = bcf86cd799
counter = 4427793 (0x439011)The MongoDB manual's id: its 4-byte prefix is a 2012 second; counter 4427793.
fffffffffffffffffffffffftimestamp = 2106-02-07T06:28:15.000Z (4294967295000 ms)
random = ffffffffff
counter = 16777215 (0xffffff)The largest ObjectId: unsigned 4-byte seconds cap on 2106-02-07.
Every example on this page is executed against the same engine that powers the tool, on every build.
Gotchas worth knowing
Ordered only to the second
Within one second, order is the per-process counter, never a global sequence across shards.
Five random bytes, not machine+PID
Pre-3.4 drivers packed machine and process ids here; the spec now uses 5 random bytes.
Time runs out in 2106
Unsigned 4-byte seconds cap at 2106-02-07T06:28:15Z, then the field wraps.
Common errors
Not a MongoDB ObjectId — expected 24 hex characters, this has 32.- A 32-character value is usually a hyphen-stripped UUID — the decoder names the length.
10,000 is the browser-side cap — for more, script it in the MongoDB shell: mongosh --quiet --eval 'for (let i=0;i<50000;i++) print(ObjectId().toHexString())'- The 10,000 cap keeps generation instant; for more, the refusal hands you a mongosh loop.
FAQ
How do I get the timestamp from a MongoDB ObjectId?
Read the first 8 hex digits — 4 bytes — as unsigned Unix seconds; paste it to see the UTC time.
Are ObjectIds guaranteed unique or ordered?
Unique in practice, ordered only to the second, then by a per-process counter.
Is an ObjectId a good primary key or a secret?
A fine default _id — compact, client-generated — but never a secret: it leaks a creation time.
Keyboard shortcuts
- ⌘/Ctrl + Enter
- Regenerate — replace the batch with fresh ObjectIds.
- ⌘/Ctrl + S
- Download the batch as .txt.
- ⌘/Ctrl + C
- Copy all ObjectIds when nothing is selected and focus is in the tool.
- ⌘/Ctrl + Shift + C
- Copy all ObjectIds even while a selection is active.
- t
- Cycle the color theme (outside text fields).
- ? or ⌘/Ctrl + /
- Open the shortcut help overlay.
- Esc
- Close an open dialog.