Q4: Explain the structure of a MongoDB ObjectId.

An ObjectId is a 12-byte BSON value designed to guarantee uniqueness across distributed systems without a central authority:

  • 4 bytes: Timestamp value (seconds since epoch).
  • 5 bytes: Random value unique to the machine and process.
  • 3 bytes: Incrementing counter initialized to a random value.
Key Takeaways
  • Total size: 12 bytes.

  • First 4 bytes encode a UTC timestamp, allowing natural sorting by creation time.

Knowledge Check

How many bytes does a standard MongoDB ObjectId consume?