MongoDB C++ Driver
mongocxx-3.0.2
|
Class representing a MongoDB database. More...
#include <database.hpp>
Public Member Functions | |
database () noexcept | |
Default constructs a new database. More... | |
database (database &&) noexcept | |
Move constructs a database. | |
database & | operator= (database &&) noexcept |
Move assigns a database. | |
database (const database &) | |
Copy constructs a database. | |
database & | operator= (const database &) |
Copy assigns a database. | |
~database () | |
Destroys a database. | |
operator bool () const noexcept | |
Returns true if the client is valid, meaning it was not default constructed or moved from. | |
bsoncxx::document::value | run_command (bsoncxx::document::view_or_value command) |
Runs a command against this database. More... | |
class collection | create_collection (bsoncxx::string::view_or_value name, const options::create_collection &options=options::create_collection()) |
Explicitly creates a collection in this database with the specified options. More... | |
bsoncxx::document::value | modify_collection (stdx::string_view name, const options::modify_collection &options=options::modify_collection()) |
Modify an existing collection. More... | |
void | drop () |
Drops the database and all its collections. More... | |
bool | has_collection (bsoncxx::string::view_or_value name) const |
Checks whether this database contains a collection having the given name. More... | |
cursor | list_collections (bsoncxx::document::view_or_value filter={}) |
Enumerates the collections in this database. More... | |
stdx::string_view | name () const |
Get the name of this database. More... | |
void | read_concern (class read_concern rc) |
Sets the read_concern for this database. More... | |
class read_concern | read_concern () const |
The current read concern for this database. More... | |
void | read_preference (class read_preference rp) |
Sets the read_preference for this database. More... | |
class read_preference | read_preference () const |
The current read preference for this database. More... | |
void | write_concern (class write_concern wc) |
Sets the write_concern for this database. More... | |
class write_concern | write_concern () const |
The current write_concern for this database. More... | |
class collection | collection (bsoncxx::string::view_or_value name) const |
Access a collection (logical grouping of documents) within this database. More... | |
class collection | operator[] (bsoncxx::string::view_or_value name) const |
Allows the db["collection_name"] syntax to be used to access a collection within this database. More... | |
Class representing a MongoDB database.
Acts as a gateway for accessing collections that are contained within a database. It inherits all of its default settings from the client that creates it.
|
noexcept |
Default constructs a new database.
The database is not valid for use and is equivalent to the state of a moved-from database. The only valid actions to take with a default constructed database are to assign to it, or destroy it.
class collection mongocxx::database::collection | ( | bsoncxx::string::view_or_value | name | ) | const |
Access a collection (logical grouping of documents) within this database.
name | the name of the collection to get. |
class collection mongocxx::database::create_collection | ( | bsoncxx::string::view_or_value | name, |
const options::create_collection & | options = options::create_collection() |
||
) |
Explicitly creates a collection in this database with the specified options.
name | the new collection's name. |
options | the options for the new collection. |
mongocxx::operation_exception | if the operation fails. |
void mongocxx::database::drop | ( | ) |
Drops the database and all its collections.
mongocxx::operation_exception | if the operation fails. |
bool mongocxx::database::has_collection | ( | bsoncxx::string::view_or_value | name | ) | const |
Checks whether this database contains a collection having the given name.
name | the name of the collection. |
mongocxx::operation_exception | if the underlying 'listCollections' command fails. |
cursor mongocxx::database::list_collections | ( | bsoncxx::document::view_or_value | filter = {} | ) |
Enumerates the collections in this database.
filter | An optional query expression to filter the returned collections. |
mongocxx::operation_exception | if the underlying 'listCollections' command fails. |
bsoncxx::document::value mongocxx::database::modify_collection | ( | stdx::string_view | name, |
const options::modify_collection & | options = options::modify_collection() |
||
) |
Modify an existing collection.
name | the name of the collection to be modified. |
options | the modifications to be performed. |
stdx::string_view mongocxx::database::name | ( | ) | const |
Get the name of this database.
collection mongocxx::database::operator[] | ( | bsoncxx::string::view_or_value | name | ) | const |
Allows the db["collection_name"] syntax to be used to access a collection within this database.
name | the name of the collection to get. |
void mongocxx::database::read_concern | ( | class read_concern | rc | ) |
Sets the read_concern for this database.
rc | The new read_concern |
class read_concern mongocxx::database::read_concern | ( | ) | const |
The current read concern for this database.
If the read_concern is not explicitly set on this database object, it inherits the read_concern from its parent client object.
void mongocxx::database::read_preference | ( | class read_preference | rp | ) |
Sets the read_preference for this database.
rp | the new read_preference. |
class read_preference mongocxx::database::read_preference | ( | ) | const |
The current read preference for this database.
bsoncxx::document::value mongocxx::database::run_command | ( | bsoncxx::document::view_or_value | command | ) |
Runs a command against this database.
command | document representing the command to be run. |
mongocxx::operation_exception | if the operation fails. |
class write_concern mongocxx::database::write_concern | ( | ) | const |
The current write_concern for this database.
void mongocxx::database::write_concern | ( | class write_concern | wc | ) |
Sets the write_concern for this database.