MongoDB C++ Driver mongocxx-4.0.0
Loading...
Searching...
No Matches
mongocxx::v_noabi::database Class Reference

#include <mongocxx/v_noabi/mongocxx/database.hpp>

Description

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.

Public Member Functions

 database () 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.
 
 database (const database &)
 Copy constructs a database.
 
 database (database &&) noexcept
 Move constructs a database.
 
 ~database ()
 Destroys a database.
 
cursor aggregate (const client_session &session, const pipeline &pipeline, const options::aggregate &options=options::aggregate())
 Runs an aggregation framework pipeline against this database for pipeline stages that do not require an underlying collection, such as $currentOp and $listLocalSessions.
 
cursor aggregate (const pipeline &pipeline, const options::aggregate &options=options::aggregate())
 Runs an aggregation framework pipeline against this database for pipeline stages that do not require an underlying collection, such as $currentOp and $listLocalSessions.
 
mongocxx::v_noabi::collection collection (bsoncxx::v_noabi::string::view_or_value name) const
 Access a collection (logical grouping of documents) within this database.
 
mongocxx::v_noabi::collection create_collection (bsoncxx::v_noabi::stdx::string_view name, bsoncxx::v_noabi::document::view_or_value collection_options={}, const bsoncxx::v_noabi::stdx::optional< write_concern > &write_concern={})
 Explicitly creates a collection in this database with the specified options.
 
mongocxx::v_noabi::collection create_collection (const client_session &session, bsoncxx::v_noabi::stdx::string_view name, bsoncxx::v_noabi::document::view_or_value collection_options={}, const bsoncxx::v_noabi::stdx::optional< write_concern > &write_concern={})
 Explicitly creates a collection in this database with the specified options.
 
void drop (const bsoncxx::v_noabi::stdx::optional< mongocxx::v_noabi::write_concern > &write_concern={})
 Drops the database and all its collections.
 
void drop (const client_session &session, const bsoncxx::v_noabi::stdx::optional< mongocxx::v_noabi::write_concern > &write_concern={})
 Drops the database and all its collections.
 
gridfs::bucket gridfs_bucket (const options::gridfs::bucket &options=options::gridfs::bucket()) const
 Access a GridFS bucket within this database.
 
bool has_collection (bsoncxx::v_noabi::string::view_or_value name) const
 Checks whether this database contains a collection having the given name.
 
std::vector< std::string > list_collection_names (bsoncxx::v_noabi::document::view_or_value filter={})
 Enumerates the collection names in this database.
 
std::vector< std::string > list_collection_names (const client_session &session, bsoncxx::v_noabi::document::view_or_value filter={})
 Enumerates the collection names in this database.
 
cursor list_collections (bsoncxx::v_noabi::document::view_or_value filter={})
 Enumerates the collections in this database.
 
cursor list_collections (const client_session &session, bsoncxx::v_noabi::document::view_or_value filter={})
 Enumerates the collections in this database.
 
bsoncxx::v_noabi::stdx::string_view name () const
 Get the name of this database.
 
 operator bool () const noexcept
 Returns true if the client is valid, meaning it was not default constructed or moved from.
 
databaseoperator= (const database &)
 Copy assigns a database.
 
databaseoperator= (database &&) noexcept
 Move assigns a database.
 
mongocxx::v_noabi::collection operator[] (bsoncxx::v_noabi::string::view_or_value name) const
 Allows the db["collection_name"] syntax to be used to access a collection within this database.
 
mongocxx::v_noabi::read_concern read_concern () const
 The current read concern for this database.
 
void read_concern (mongocxx::v_noabi::read_concern rc)
 Sets the read_concern for this database.
 
mongocxx::v_noabi::read_preference read_preference () const
 The current read preference for this database.
 
void read_preference (mongocxx::v_noabi::read_preference rp)
 Sets the read_preference for this database.
 
bsoncxx::v_noabi::document::value run_command (bsoncxx::v_noabi::document::view_or_value command)
 Runs a command against this database.
 
bsoncxx::v_noabi::document::value run_command (bsoncxx::v_noabi::document::view_or_value command, uint32_t server_id)
 Executes a command on a specific server using this database.
 
bsoncxx::v_noabi::document::value run_command (const client_session &session, bsoncxx::v_noabi::document::view_or_value command)
 Runs a command against this database.
 
change_stream watch (const client_session &session, const options::change_stream &options={})
 
change_stream watch (const client_session &session, const pipeline &pipe, const options::change_stream &options={})
 Gets a change stream on this database.
 
change_stream watch (const options::change_stream &options={})
 Gets a change stream on this database with an empty pipeline. Change streams are only supported with a "majority" read concern or no read concern.
 
change_stream watch (const pipeline &pipe, const options::change_stream &options={})
 Gets a change stream on this database. Change streams are only supported with a "majority" read concern or no read concern.
 
mongocxx::v_noabi::write_concern write_concern () const
 The current write_concern for this database.
 
void write_concern (mongocxx::v_noabi::write_concern wc)
 Sets the write_concern for this database.
 

Constructor & Destructor Documentation

◆ database() [1/3]

mongocxx::v_noabi::database::database ( )
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.

◆ database() [2/3]

mongocxx::v_noabi::database::database ( database && )
noexcept

Move constructs a database.

◆ database() [3/3]

mongocxx::v_noabi::database::database ( const database & )

Copy constructs a database.

◆ ~database()

mongocxx::v_noabi::database::~database ( )

Destroys a database.

Member Function Documentation

◆ aggregate() [1/2]

cursor mongocxx::v_noabi::database::aggregate ( const client_session & session,
const pipeline & pipeline,
const options::aggregate & options = options::aggregate() )

Runs an aggregation framework pipeline against this database for pipeline stages that do not require an underlying collection, such as $currentOp and $listLocalSessions.

Parameters
sessionThe mongocxx::v_noabi::client_session with which to perform the aggregation.
pipelineThe pipeline of aggregation operations to perform.
optionsOptional arguments, see mongocxx::v_noabi::options::aggregate.
Returns
A mongocxx::v_noabi::cursor with the results. If the query fails, the cursor throws mongocxx::v_noabi::query_exception when the returned cursor is iterated.
See also
Note
In order to pass a read concern to this, you must use the database level set read concern - database::read_concern(rc). (Write concern supported only for MongoDB 3.4+).

◆ aggregate() [2/2]

cursor mongocxx::v_noabi::database::aggregate ( const pipeline & pipeline,
const options::aggregate & options = options::aggregate() )

Runs an aggregation framework pipeline against this database for pipeline stages that do not require an underlying collection, such as $currentOp and $listLocalSessions.

Parameters
pipelineThe pipeline of aggregation operations to perform.
optionsOptional arguments, see mongocxx::v_noabi::options::aggregate.
Returns
A mongocxx::v_noabi::cursor with the results. If the query fails, the cursor throws mongocxx::v_noabi::query_exception when the returned cursor is iterated.
See also
Note
In order to pass a read concern to this, you must use the database level set read concern - database::read_concern(rc). (Write concern supported only for MongoDB 3.4+).

◆ collection()

mongocxx::v_noabi::collection mongocxx::v_noabi::database::collection ( bsoncxx::v_noabi::string::view_or_value name) const

Access a collection (logical grouping of documents) within this database.

Parameters
namethe name of the collection to get.
Returns
the collection.

◆ create_collection() [1/2]

mongocxx::v_noabi::collection mongocxx::v_noabi::database::create_collection ( bsoncxx::v_noabi::stdx::string_view name,
bsoncxx::v_noabi::document::view_or_value collection_options = {},
const bsoncxx::v_noabi::stdx::optional< write_concern > & write_concern = {} )

Explicitly creates a collection in this database with the specified options.

See also
Note
This function can also be used to create a Time Series Collection. See: https://www.mongodb.com/docs/manual/core/timeseries-collections/
Parameters
namethe new collection's name.
collection_optionsthe options for the new collection.
write_concernthe write concern to use for this operation. Will default to database set write concern if none passed here.
Exceptions
mongocxx::v_noabi::operation_exceptionif the operation fails.

◆ create_collection() [2/2]

mongocxx::v_noabi::collection mongocxx::v_noabi::database::create_collection ( const client_session & session,
bsoncxx::v_noabi::stdx::string_view name,
bsoncxx::v_noabi::document::view_or_value collection_options = {},
const bsoncxx::v_noabi::stdx::optional< write_concern > & write_concern = {} )

Explicitly creates a collection in this database with the specified options.

See also
Note
This function can also be used to create a Time Series Collection. See: https://www.mongodb.com/docs/manual/core/timeseries-collections/
Parameters
sessionThe mongocxx::v_noabi::client_session with which to perform the create operation.
namethe new collection's name.
collection_optionsthe options for the new collection.
write_concernthe write concern to use for this operation. Will default to database set write concern if none passed here.
Exceptions
mongocxx::v_noabi::operation_exceptionif the operation fails.

◆ drop() [1/2]

void mongocxx::v_noabi::database::drop ( const bsoncxx::v_noabi::stdx::optional< mongocxx::v_noabi::write_concern > & write_concern = {})

Drops the database and all its collections.

Parameters
write_concern(optional) The write concern to be used for this operation. If not passed here, the write concern set on the database will be used.
Exceptions
mongocxx::v_noabi::operation_exceptionif the operation fails.
See also

◆ drop() [2/2]

void mongocxx::v_noabi::database::drop ( const client_session & session,
const bsoncxx::v_noabi::stdx::optional< mongocxx::v_noabi::write_concern > & write_concern = {} )

Drops the database and all its collections.

Parameters
sessionThe mongocxx::v_noabi::client_session with which to perform the aggregation.
write_concern(optional) The write concern to be used for this operation. If not passed here, the write concern set on the database will be used.
Exceptions
mongocxx::v_noabi::operation_exceptionif the operation fails.
See also

◆ gridfs_bucket()

gridfs::bucket mongocxx::v_noabi::database::gridfs_bucket ( const options::gridfs::bucket & options = options::gridfs::bucket()) const

Access a GridFS bucket within this database.

Parameters
optionsThe options for the bucket.
Returns
The GridFS bucket.
Note
See the class comment for gridfs::bucket for more information about GridFS.
Exceptions
mongocxx::v_noabi::logic_errorif options are invalid.

◆ has_collection()

bool mongocxx::v_noabi::database::has_collection ( bsoncxx::v_noabi::string::view_or_value name) const

Checks whether this database contains a collection having the given name.

Parameters
namethe name of the collection.
Returns
bool whether the collection exists in this database.
Exceptions
mongocxx::v_noabi::operation_exceptionif the underlying 'listCollections' command fails.

◆ list_collection_names() [1/2]

std::vector< std::string > mongocxx::v_noabi::database::list_collection_names ( bsoncxx::v_noabi::document::view_or_value filter = {})

Enumerates the collection names in this database.

Parameters
filterAn optional query expression to filter the returned collection names.
Returns
std::vector<std::string> containing the collection names.
Exceptions
mongocxx::v_noabi::operation_exceptionif the underlying 'listCollections' command fails.
See also

◆ list_collection_names() [2/2]

std::vector< std::string > mongocxx::v_noabi::database::list_collection_names ( const client_session & session,
bsoncxx::v_noabi::document::view_or_value filter = {} )

Enumerates the collection names in this database.

Parameters
sessionThe mongocxx::v_noabi::client_session with which to perform the aggregation.
filterAn optional query expression to filter the returned collection names.
Returns
std::vector<std::string> containing the collection names.
Exceptions
mongocxx::v_noabi::operation_exceptionif the underlying 'listCollections' command fails.
See also

◆ list_collections() [1/2]

cursor mongocxx::v_noabi::database::list_collections ( bsoncxx::v_noabi::document::view_or_value filter = {})

Enumerates the collections in this database.

Parameters
filterAn optional query expression to filter the returned collections.
Returns
mongocxx::v_noabi::cursor containing the collection information.
See also

◆ list_collections() [2/2]

cursor mongocxx::v_noabi::database::list_collections ( const client_session & session,
bsoncxx::v_noabi::document::view_or_value filter = {} )

Enumerates the collections in this database.

Parameters
sessionThe mongocxx::v_noabi::client_session with which to perform the aggregation.
filterAn optional query expression to filter the returned collections.
Returns
mongocxx::v_noabi::cursor containing the collection information.
See also

◆ name()

bsoncxx::v_noabi::stdx::string_view mongocxx::v_noabi::database::name ( ) const

Get the name of this database.

Returns
the name of this database.

◆ operator bool()

mongocxx::v_noabi::database::operator bool ( ) const
explicitnoexcept

Returns true if the client is valid, meaning it was not default constructed or moved from.

◆ operator=() [1/2]

database & mongocxx::v_noabi::database::operator= ( const database & )

Copy assigns a database.

◆ operator=() [2/2]

database & mongocxx::v_noabi::database::operator= ( database && )
noexcept

Move assigns a database.

◆ operator[]()

mongocxx::v_noabi::collection mongocxx::v_noabi::database::operator[] ( bsoncxx::v_noabi::string::view_or_value name) const
inline

Allows the db["collection_name"] syntax to be used to access a collection within this database.

Parameters
namethe name of the collection to get.
Returns
the collection.

◆ read_concern() [1/2]

mongocxx::v_noabi::read_concern mongocxx::v_noabi::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.

Returns
the current read_concern

◆ read_concern() [2/2]

void mongocxx::v_noabi::database::read_concern ( mongocxx::v_noabi::read_concern rc)

Sets the read_concern for this database.

Note
Modifications at this level do not affect existing collection instances that have come from this database, but do affect new ones. New collections will receive a copy of the new read_concern for this database upon instantiation.
Parameters
rcThe new read_concern
See also

◆ read_preference() [1/2]

mongocxx::v_noabi::read_preference mongocxx::v_noabi::database::read_preference ( ) const

The current read preference for this database.

See also
Returns
the current read_preference

◆ read_preference() [2/2]

void mongocxx::v_noabi::database::read_preference ( mongocxx::v_noabi::read_preference rp)

Sets the read_preference for this database.

Note
Modifications at this level do not affect existing collection instances that have come from this database, but do affect new ones. New collections will receive a copy of the new read_preference for this database upon instantiation.
See also
Parameters
rpthe new read_preference.

◆ run_command() [1/3]

bsoncxx::v_noabi::document::value mongocxx::v_noabi::database::run_command ( bsoncxx::v_noabi::document::view_or_value command)

Runs a command against this database.

See also
Parameters
commanddocument representing the command to be run.
Returns
the result of executing the command.
Exceptions
mongocxx::v_noabi::operation_exceptionif the operation fails.

◆ run_command() [2/3]

bsoncxx::v_noabi::document::value mongocxx::v_noabi::database::run_command ( bsoncxx::v_noabi::document::view_or_value command,
uint32_t server_id )

Executes a command on a specific server using this database.

See also
Parameters
commanddocument representing the command to be run.
server_idspecifying which server to use.
Returns
the result of executing the command.
Exceptions
mongocxx::v_noabi::operation_exceptionif the operation fails.

◆ run_command() [3/3]

bsoncxx::v_noabi::document::value mongocxx::v_noabi::database::run_command ( const client_session & session,
bsoncxx::v_noabi::document::view_or_value command )

Runs a command against this database.

See also
Parameters
sessionThe mongocxx::v_noabi::client_session with which to run the command.
commanddocument representing the command to be run.
Returns
the result of executing the command.
Exceptions
mongocxx::v_noabi::operation_exceptionif the operation fails.

◆ watch() [1/4]

change_stream mongocxx::v_noabi::database::watch ( const client_session & session,
const options::change_stream & options = {} )
Parameters
sessionThe mongocxx::v_noabi::client_session with which to perform the watch operation.
optionsThe options to use when creating the change stream.
Returns
A change stream on this database.
See also

◆ watch() [2/4]

change_stream mongocxx::v_noabi::database::watch ( const client_session & session,
const pipeline & pipe,
const options::change_stream & options = {} )

Gets a change stream on this database.

Parameters
sessionThe mongocxx::v_noabi::client_session with which to perform the watch operation.
pipeThe aggregation pipeline to be used on the change notifications.
optionsThe options to use when creating the change stream.
Returns
A change stream on this database.
See also

◆ watch() [3/4]

change_stream mongocxx::v_noabi::database::watch ( const options::change_stream & options = {})

Gets a change stream on this database with an empty pipeline. Change streams are only supported with a "majority" read concern or no read concern.

Parameters
optionsThe options to use when creating the change stream.
Returns
A change stream on this database.
See also

◆ watch() [4/4]

change_stream mongocxx::v_noabi::database::watch ( const pipeline & pipe,
const options::change_stream & options = {} )

Gets a change stream on this database. Change streams are only supported with a "majority" read concern or no read concern.

Parameters
pipeThe aggregation pipeline to be used on the change notifications. Only a subset of pipeline operations are supported for change streams. For more information see the change streams documentation.
optionsThe options to use when creating the change stream.
Returns
A change stream on this database.
See also

◆ write_concern() [1/2]

mongocxx::v_noabi::write_concern mongocxx::v_noabi::database::write_concern ( ) const

The current write_concern for this database.

Returns
the current write_concern

◆ write_concern() [2/2]

void mongocxx::v_noabi::database::write_concern ( mongocxx::v_noabi::write_concern wc)

Sets the write_concern for this database.

Note
Modifications at this level do not affect existing collection instances that have come from this database, but do affect new ones as new collections will receive a copy of the write_concern of this database upon instantiation.

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