MongoDB ObjectId Generator Online — Generate & Inspect BSON IDs
Generate MongoDB-compatible ObjectIds (12-byte BSON identifiers) or inspect an existing ObjectId to extract its embedded timestamp. Use it to seed fixtures without booting a Mongo client, debug document IDs in logs, or back-fill missing `_id` fields. The generator follows the same algorithm the official drivers use and runs entirely in your browser.
Features
Spec-compliant generation
Matches the structure used by the MongoDB drivers: 4-byte timestamp, 5-byte random, 3-byte counter.
Inspect any ObjectId
Paste an existing ObjectId to extract the timestamp and verify the 24-character hex format.
Bulk generation
Generate many ObjectIds at once for seed data, stress tests, or import scripts.
Pure JavaScript
No backend, no driver. Everything runs in the browser.
How to generate a MongoDB ObjectId online
Create or inspect ObjectIds in three steps.
- Choose actionGenerate (new ObjectId) or Inspect (parse an existing one).
- Configure quantityFor generation, pick how many IDs you need.
- Inspect outputFor inspection, paste a 24-character hex string and read the embedded timestamp and random/counter parts.
Examples
Generated ObjectId
count=1
65a8d7e2c4a1b3f6d9e2f0a1
The first 4 bytes (`65a8d7e2`) encode the creation timestamp in seconds since epoch.
Inspect an ObjectId
65a8d7e2c4a1b3f6d9e2f0a1
Timestamp: 2024-01-18T05:32:18Z Random: c4a1b3f6d9 Counter: e2f0a1
Frequently Asked Questions
- How is a MongoDB ObjectId structured?
- An ObjectId is 12 bytes (24 hex characters): 4 bytes timestamp (seconds since epoch), 5 bytes random per-process value, and a 3-byte incrementing counter. This balances uniqueness with sortability by time.
- Can I sort documents by `_id`?
- Yes. Because the first 4 bytes are a timestamp, sorting ObjectIds approximately sorts documents by creation order — useful for many queries.
- Will the generated IDs collide with MongoDB-generated ones?
- No, in practice. The random component differs per process and the counter cycles independently. Treat them as unique just like driver-generated IDs.
- Why not use a UUID instead?
- UUIDs are 16 bytes vs ObjectId's 12 bytes and lack the embedded timestamp. ObjectId is the idiomatic MongoDB choice; UUID is a portable alternative if you need cross-database consistency.
- Is the timestamp accurate to milliseconds?
- No. The ObjectId timestamp is in whole seconds. For sub-second ordering, add an explicit `createdAt` field with millisecond precision.