LLI Wiki — My Digital Knowledge Base

MongoDB: structure of the _id field (ObjectId)

Breakdown of the 12 bytes of a MongoDB ObjectId: timestamp, machine, process and counter.

Every MongoDB document has an _id field that makes it unique in its collection. If the application does not provide one at insertion, MongoDB generates an ObjectId for the document.

Structure of an ObjectId

An ObjectId is 12 bytes, written as 24 hexadecimal characters (2 characters per byte):

Bytes Content Hex characters
4 Timestamp of the creation 8
3 Machine identifier 6
2 Process identifier of the mongod server 4
3 Incremental counter 6

Notes

Mastodon LLIMastodon SocialFosstodon