ObjectIDs(3) None

COMPOSITION

\[bu]
4 bytes : The UNIX timestamp in big-endian format.
\[bu]
3 bytes : The first 3 bytes of MD5(hostname) \&.
\[bu]
2 bytes : The pid_t of the current process. Alternatively the task-id if configured.
\[bu]
3 bytes : A 24-bit monotonic counter incrementing from rand(3) in big-endian.

SORTING OBJECTIDS

The typical way to sort in C is using qsort(3) \&. Therefore, Libbson provides a qsort(3) compatible callback function named bson_oid_compare(3) \&. It returns less than 1 , greater than 1 , or 0 depending on the equality of two bson_oid_t structures.

COMPARING OBJECT IDS

If you simply want to compare two bson_oid_t structures for equality, use bson_oid_equal(3) \&.

GENERATING

To generate a bson_oid_t , you may use the following.

PARSING OBJECTID STRINGS

You can also parse a string contianing a bson_oid_t \&. The input string MUST be 24 characters or more in length.

If you need to parse may bson_oid_t in a tight loop and can guarantee the data is safe, you might consider using the inline variant. It will be inlined into your code and reduce the need for a foreign function call.

HASHING OBJECTIDS

If you need to store items in a hashtable, you may want to use the bson_oid_t as the key. Libbson provides a hash function for just this purpose. It is based on DJB hash.

FETCHING OBJECTID CREATION TIME

You can easily fetch the time that a bson_oid_t was generated using bson_oid_get_time_t(3) \&.

COLOPHON

This page is part of libbson. Please report any bugs at https://jira.mongodb.org/browse/CDRIVER.