ObjectId is a 12-byte BSON type, constructed using:
- a 4-byte timestamp,
- a 3-byte machine identifier,
- a 2-byte process id, and
- a 3-byte counter, starting with a random value.
In MongoDB, documents stored in a collection require a unique _id field that acts as a primary key. Because ObjectIds are small, most likely unique, and fast to generate, MongoDB uses ObjectIds as the default value for the _id field if the _id field is not specified; i.e., the mongod adds the _id field and generates a unique ObjectId to assign as its value.
const std::string & id
Creates an ObjectId from a string.
The string must contain a hexadecimal representation of an object ID. This means a string of 24 characters.
Creates an ObjectId by copying another one.
Destroys the ObjectId.
Timestamp timestamp() const;
Returns the timestamp which is stored in the first four bytes of the id
const std::string & fmt = "%02x"
Returns the id in string format. The fmt parameter specifies the formatting used for individual members of the ID char array.