MongoDB C++ Driver  mongocxx-3.0.0
Classes | Public Member Functions | List of all members
bsoncxx::oid Class Reference

Represents a MongoDB ObjectId. More...

#include <oid.hpp>

Classes

struct  init_tag_t
 

Public Member Functions

 oid ()
 Constructs an uninitialized oid.
 
 oid (init_tag_t tag)
 Constructs an oid and initializes it to a newly generated ObjectId. More...
 
 oid (const char *bytes, std::size_t len)
 Constructs an oid initializes it to the contents of the provided buffer. More...
 
 oid (const string::view_or_value &str)
 Constructs an oid and initializes it from the provided hex string. More...
 
std::string to_string () const
 Converts this oid to a hexadecimal string. More...
 
 operator bool () const
 Conversion operator that indicates that the oid is initialized. More...
 
std::time_t get_time_t () const
 Extracts the timestamp portion of the underlying ObjectId. More...
 
const char * bytes () const
 An accessor for the internal data buffer in the oid. More...
 
bool operator< (const oid &lhs, const oid &rhs)
 Relational operators for OIDs.
 
bool operator> (const oid &lhs, const oid &rhs)
 Relational operators for OIDs.
 
bool operator<= (const oid &lhs, const oid &rhs)
 Relational operators for OIDs.
 
bool operator>= (const oid &lhs, const oid &rhs)
 Relational operators for OIDs.
 
bool operator== (const oid &lhs, const oid &rhs)
 Relational operators for OIDs.
 
bool operator!= (const oid &lhs, const oid &rhs)
 Relational operators for OIDs.
 

Detailed Description

Represents a MongoDB ObjectId.

As this BSON type is used within the MongoDB server as a primary key for each document, it is useful for representing a 'pointer' to another document.

Note
we use 'oid' to refer to this concrete class. We use 'ObjectId' to refer to the BSON type.
See also
http://docs.mongodb.org/manual/reference/object-id/

Constructor & Destructor Documentation

bsoncxx::oid::oid ( init_tag_t  tag)
explicit

Constructs an oid and initializes it to a newly generated ObjectId.

Parameters
tagA bsoncxx::oid::init_tag used to dispatch this overload.
bsoncxx::oid::oid ( const char *  bytes,
std::size_t  len 
)
explicit

Constructs an oid initializes it to the contents of the provided buffer.

Parameters
bytesA pointer a buffer containing a valid ObjectId.
lenThe length of the buffer. Should be 12.
bsoncxx::oid::oid ( const string::view_or_value str)
explicit

Constructs an oid and initializes it from the provided hex string.

Parameters
strA string of a hexadecimal representation of a valid ObjectId.

Member Function Documentation

const char* bsoncxx::oid::bytes ( ) const

An accessor for the internal data buffer in the oid.

Returns
A pointer to the internal buffer holding the oid bytes.
std::time_t bsoncxx::oid::get_time_t ( ) const

Extracts the timestamp portion of the underlying ObjectId.

Returns
A std::time_t initialized to the timestamp.
bsoncxx::oid::operator bool ( ) const
explicit

Conversion operator that indicates that the oid is initialized.

Returns
True if the oid is initialized.
std::string bsoncxx::oid::to_string ( ) const

Converts this oid to a hexadecimal string.

Returns
A hexadecimal string representation of this ObjectId.

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