mongo::OID Class Reference

Object ID type. More...

#include <oid.h>

List of all members.

Classes

struct  MachineAndPid

Public Member Functions

 OID (const string &s)
 init from a 24 char hex string
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
string str () const
string toString () const
void init ()
 sets the contents to a new oid / randomized value
void init (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.
time_t asTimeT ()
Date_t asDateT ()
bool isSet () const

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.

string mongo::OID::str (  )  const [inline]
Returns:
the object ID output as 24 hex digits

The documentation for this class was generated from the following files:
Generated on Wed Sep 14 01:46:41 2011 for MongoDB by  doxygen 1.6.3