Poco::MongoDB

class ObjectId

Library: MongoDB
Package: MongoDB
Header: Poco/MongoDB/ObjectId.h

Description

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.

Member Summary

Member Functions: timestamp, toString

Types

Ptr

typedef SharedPtr < ObjectId > Ptr;

Constructors

ObjectId

ObjectId(
    const std::string & id
);

Constructor. The string must contain a hexidecimal representation of an object id. This means a string of 24 characters.

ObjectId

ObjectId(
    const ObjectId & copy
);

Copy constructor.

Destructor

~ObjectId virtual

virtual ~ObjectId();

Destructor

Member Functions

timestamp inline

Timestamp timestamp() const;

Returns the timestamp which is stored in the first four bytes of the id

toString

std::string toString(
    const std::string & fmt = "%02x"
) const;

Returns the id in string format. The fmt parameter specifies the formatting used for individual members of the ID char array.