About mongodb objectid generator
A MongoDB ObjectId is a 12-byte identifier. The first four bytes are a timestamp, so you can read when it was created.
Structure
- 4 bytes: seconds since the Unix epoch.
- 5 bytes: a random value unique to the machine and process.
- 3 bytes: a counter.
Uses
Generate IDs for test data, or paste one to read its creation time.
A worked example
The ObjectId 507f1f77bcf86cd799439011 starts with the timestamp 507f1f77, which is the time of creation, so you can read when a document was made even if it has no date field. The tool shows that date and generates new IDs for testing.
Good to know
- ObjectIds are roughly increasing, which helps indexes.
- They are unique but not secret, so do not use them as access tokens.
- In code you wrap the string with ObjectId() before querying by _id.
