MongoDB C++ Driver
mongocxx-3.0.0
|
Class representing a client connection to MongoDB. More...
#include <client.hpp>
Public Member Functions | |
client () noexcept | |
Default constructs a new client. More... | |
client (const class uri &mongodb_uri, const options::client &options=options::client()) | |
Creates a new client connection to MongoDB. More... | |
client (client &&) noexcept | |
Move constructs a client. | |
client & | operator= (client &&) noexcept |
Move assigns a client. | |
~client () | |
Destroys a client. | |
operator bool () const noexcept | |
Returns true if the client is valid, meaning it was not default constructed or moved from. | |
void | read_concern (class read_concern rc) |
Sets the read concern for this client. More... | |
class read_concern | read_concern () const |
Returns the current read concern for this client. More... | |
void | read_preference (class read_preference rp) |
Sets the read preference for this client. More... | |
class read_preference | read_preference () const |
Returns the current read preference for this client. More... | |
class uri | uri () const |
Returns the current uri for this client. More... | |
void | write_concern (class write_concern wc) |
Sets the write concern for this client. More... | |
class write_concern | write_concern () const |
Returns the current write concern for this client. More... | |
class database | database (bsoncxx::string::view_or_value name) const & |
Obtains a database that represents a logical grouping of collections on a MongoDB server. More... | |
class database | operator[] (bsoncxx::string::view_or_value name) const & |
Allows the syntax client ["db_name"] as a convenient shorthand for the client::database() method by implementing the array subscript operator. More... | |
cursor | list_databases () const |
Enumerates the databases in the client. More... | |
Class representing a client connection to MongoDB.
Acts as a logical gateway for working with databases contained within a MongoDB server.
Databases that are created via this client inherit the read_concern
, read_preference
, and write_concern
settings of this client when they are created. The lifetimes of objects created via a client object (databases, collections, cursors, etc...) must be a subset of the lifetime of the client that created them.
Example:
|
noexcept |
Default constructs a new client.
The client is not connected and is equivalent to the state of a moved-from client. The only valid actions to take with a default constructed 'client' are to assign to it, or destroy it.
mongocxx::client::client | ( | const class uri & | mongodb_uri, |
const options::client & | options = options::client() |
||
) |
Creates a new client connection to MongoDB.
mongodb_uri | A MongoDB URI representing the connection parameters |
options | Additional options that cannot be specified via the mongodb_uri |
class database mongocxx::client::database | ( | bsoncxx::string::view_or_value | name | ) | const |
Obtains a database that represents a logical grouping of collections on a MongoDB server.
name | The name of the database to get |
cursor mongocxx::client::list_databases | ( | ) | const |
Enumerates the databases in the client.
exception::operation | if the underlying 'listDatabases' command fails. |
database mongocxx::client::operator[] | ( | bsoncxx::string::view_or_value | name | ) | const |
Allows the syntax client
["db_name"] as a convenient shorthand for the client::database() method by implementing the array subscript operator.
name | The name of the database. |
class read_concern mongocxx::client::read_concern | ( | ) | const |
Returns the current read concern for this client.
read_concern
void mongocxx::client::read_concern | ( | class read_concern | rc | ) |
Sets the read concern for this client.
Modifications at this level do not affect existing databases instances that have have been created by this client but do affect new ones as databases inherit the read_concern
settings of their parent upon instantiation.
rc | The new read_concern |
class read_preference mongocxx::client::read_preference | ( | ) | const |
Returns the current read preference for this client.
read_preference
void mongocxx::client::read_preference | ( | class read_preference | rp | ) |
Sets the read preference for this client.
Modifications at this level do not affect existing databases instances that have have been created by this client but do affect new ones as databases inherit the read_preference
settings of their parent upon instantiation.
rp | The new read_preference |
class uri mongocxx::client::uri | ( | ) | const |
Returns the current uri for this client.
uri
that this client was created with. void mongocxx::client::write_concern | ( | class write_concern | wc | ) |
Sets the write concern for this client.
write_concern
upon instantiation.wc | The new write concern |
class write_concern mongocxx::client::write_concern | ( | ) | const |
Returns the current write concern for this client.
write_concern