MongoDB  2.7.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
mongo::OID Class Reference

Object ID type. More...

#include <oid.h>

Public Types

enum  { kOIDSize = 12, kIncSize = 3 }
 

Public Member Functions

 OID (const std::string &s)
 init from a 24 char hex string
 
 OID (const unsigned char(&arr)[kOIDSize])
 init from a reference to a 12-byte array
 
void clear ()
 initialize to 'null'
 
const unsigned char * getData () const
 
bool operator== (const OID &r) const
 
bool operator!= (const OID &r) const
 
int compare (const OID &other) const
 
bool operator< (const OID &other) const
 
bool operator<= (const OID &other) const
 
std::string str () const
 
std::string toString () const
 
std::string toIncString () const
 
void init ()
 sets the contents to a new oid / randomized value
 
void initSequential ()
 sets the contents to a new oid guaranteed to be sequential NOT guaranteed to be globally unique only unique for this process
 
void init (const std::string &s)
 init from a 24 char hex string
 
void init (Date_t date, bool max=false)
 Set to the min/max OID that could be generated at given timestamp. More...
 
time_t asTimeT ()
 
Date_t asDateT ()
 
bool isSet () const
 
void hash_combine (size_t &seed) const
 this is not consistent do not store on disk
 

Static Public Member Functions

static OID gen ()
 
static void justForked ()
 call this after a fork to update the process id
 
static unsigned getMachineId ()
 
static void regenMachineId ()
 

Detailed Description

Object ID type.

BSON objects typically have an _id field for the object id. This field should be the first member of the object when present. class OID is a special type that is a 12 byte id which is likely to be unique to the system. You may also use other types for _id's. When _id field is missing from a BSON object, on an insert the database may insert one automatically in certain circumstances.

Warning: You must call OID::newState() after a fork().

Typical contents of the BSON ObjectID is a 12-byte value consisting of a 4-byte timestamp (seconds since epoch), a 3-byte machine id, a 2-byte process id, and a 3-byte counter. Note that the timestamp and counter fields must be stored big endian unlike the rest of BSON. This is because they are compared byte-by-byte and we want to ensure a mostly increasing order.

Member Function Documentation

void mongo::OID::init ( Date_t  date,
bool  max = false 
)

Set to the min/max OID that could be generated at given timestamp.

std::string mongo::OID::str ( ) const
inline
Returns
the object ID output as 24 hex digits
std::string mongo::OID::toIncString ( ) const
inline
Returns
the random/sequential part of the object ID as 6 hex digits

The documentation for this class was generated from the following files: