Loading...
Searching...
No Matches
mongocxx::v1::database Class Reference

`#include <mongocxx/v1/database.hpp>`

## Description

A MongoDB database.

See also
  - Databases and Collections in MongoDB (MongoDB Manual)

## Public Member Functions

| database ()
| Default initialization.
| database (database &&other) noexcept
| Move constructor.
| database (database const &other)
| Copy construction.
| ~database ()
| Destroy this object.
v1::collection | collection (bsoncxx::v1::stdx::string_view name) const
| Access the collection with the given name.
v1::gridfs::bucket | gridfs_bucket (v1::gridfs::bucket::options const &opts={}) const
| Return a GridFS bucket for this database.
bool | has_collection (bsoncxx::v1::stdx::string_view name)
| Return true when this database contains a collection with the given name.
bsoncxx::v1::stdx::string_view | name () const
| Return the name of this database.
| operator bool () const
| Return true when *this is NOT in an assign-or-destroy-only state.
database & | operator= (database &&other) noexcept
| Move assignment.
database & | operator= (database const &other)
| Copy assignment.
v1::collection | operator[] (bsoncxx::v1::stdx::string_view name) const
| Equivalent to this->collection(name).
v1::read_concern | read_concern () const
| Return the current default "readConcern" to use for operations on this database.
void | read_concern (v1::read_concern const &rc)
| Set the default "readConcern" to use for operations on this database.
v1::read_preference | read_preference () const
| Return the current default "readPreference" to use for operations on this database.
void | read_preference (v1::read_preference const &rp)
| Set the default "readPreference" to use for operations on this database.
bsoncxx::v1::document::value | run_command (bsoncxx::v1::document::view command, std::uint32_t server_id)
| Run an arbitrary database command against the requested specific server.
v1::write_concern | write_concern () const
| Return the current default "writeConcern" to use for operations on this database.
void | write_concern (v1::write_concern const &wc)
| Set the default "writeConcern" to use for operations on this database.
v1::cursor | aggregate (v1::pipeline const &pipeline, v1::aggregate_options const &opts={})
| Run an aggregation framework pipeline.
v1::cursor | aggregate (v1::client_session const &session, v1::pipeline const &pipeline, v1::aggregate_options const &opts={})
| Run an aggregation framework pipeline.
bsoncxx::v1::document::value | run_command (bsoncxx::v1::document::view command)
| Run an arbitrary database command.
bsoncxx::v1::document::value | run_command (v1::client_session const &session, bsoncxx::v1::document::view command)
| Run an arbitrary database command.
v1::collection | create_collection (bsoncxx::v1::stdx::string_view name, bsoncxx::v1::document::view opts={}, bsoncxx::v1::stdx::optional< v1::write_concern > const &wc={})
| Explicitly create a new collection or view in this database.
v1::collection | create_collection (v1::client_session const &session, bsoncxx::v1::stdx::string_view name, bsoncxx::v1::document::view opts={}, bsoncxx::v1::stdx::optional< v1::write_concern > const &wc={})
| Explicitly create a new collection or view in this database.
void | drop (bsoncxx::v1::stdx::optional< v1::write_concern > const &wc={})
| Drop this database and all associated data files.
void | drop (v1::client_session const &session, bsoncxx::v1::stdx::optional< v1::write_concern > const &wc={})
| Drop this database and all associated data files.
v1::cursor | list_collections (bsoncxx::v1::document::view filter={})
| Return an unsorted list of all collections and views in this database.
v1::cursor | list_collections (v1::client_session const &session, bsoncxx::v1::document::view filter={})
| Return an unsorted list of all collections and views in this database.
std::vector< std::string > | list_collection_names (bsoncxx::v1::document::view filter={})
| Return an unsorted list of the names of all the collections and views in this database.
std::vector< std::string > | list_collection_names (v1::client_session const &session, bsoncxx::v1::document::view filter={})
| Return an unsorted list of the names of all the collections and views in this database.
v1::change_stream | watch (v1::change_stream::options const &opts={})
| Return a change stream subscribed to this database.
v1::change_stream | watch (v1::client_session const &session, v1::change_stream::options const &opts={})
| Return a change stream subscribed to this database.
v1::change_stream | watch (v1::pipeline const &pipeline, v1::change_stream::options const &opts={})
| Return a change stream subscribed to this collection with events filtered/modified by pipeline.
v1::change_stream | watch (v1::client_session const &session, v1::pipeline const &pipeline, v1::change_stream::options const &opts={})
| Return a change stream subscribed to this collection with events filtered/modified by pipeline.

## Constructor & Destructor Documentation

## ~database()

mongocxx::v1::database::~database | ( |  | ) |

Destroy this object.

Warning
  Invalidates all associated views, collections, cursors, GridFS buckets, and change streams.

## database() [1/3]

mongocxx::v1::database::database | ( | database && | other | ) |

noexcept

Move constructor.

Postconditions:
  - other is in an assign-or-destroy-only state.

## database() [2/3]

mongocxx::v1::database::database | ( | database const & | other | ) |

Copy construction.

## database() [3/3]

mongocxx::v1::database::database | ( |  | ) |

Default initialization.

Postconditions:
  - *this is in an assign-or-destroy-only state.

## Member Function Documentation

## aggregate() [1/2]

v1::cursor mongocxx::v1::database::aggregate | ( | v1::client_session const & | session,
|  | v1::pipeline const & | pipeline,
|  | v1::aggregate_options const & | opts = {} )

Run an aggregation framework pipeline.

See also
  - aggregate (database command) (MongoDB Manual)

## aggregate() [2/2]

v1::cursor mongocxx::v1::database::aggregate | ( | v1::pipeline const & | pipeline,
|  | v1::aggregate_options const & | opts = {} )

Run an aggregation framework pipeline.

See also
  - aggregate (database command) (MongoDB Manual)

## collection()

v1::collection mongocxx::v1::database::collection | ( | bsoncxx::v1::stdx::string_view | name | ) | const

Access the collection with the given name.

## create_collection() [1/2]

v1::collection mongocxx::v1::database::create_collection | ( | bsoncxx::v1::stdx::string_view | name,
|  | bsoncxx::v1::document::view | opts = {},
|  | bsoncxx::v1::stdx::optional< v1::write_concern > const & | wc = {} )

Explicitly create a new collection or view in this database.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - create (database command) (MongoDB Manual)

## create_collection() [2/2]

v1::collection mongocxx::v1::database::create_collection | ( | v1::client_session const & | session,
|  | bsoncxx::v1::stdx::string_view | name,
|  | bsoncxx::v1::document::view | opts = {},
|  | bsoncxx::v1::stdx::optional< v1::write_concern > const & | wc = {} )

Explicitly create a new collection or view in this database.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - create (database command) (MongoDB Manual)

## drop() [1/2]

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

Drop this database and all associated data files.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - dropDatabase (database command) (MongoDB Manual)

## drop() [2/2]

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

Drop this database and all associated data files.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - dropDatabase (database command) (MongoDB Manual)

## gridfs_bucket()

v1::gridfs::bucket mongocxx::v1::database::gridfs_bucket | ( | v1::gridfs::bucket::options const & | opts = {} | ) | const

Return a GridFS bucket for this database.

Note
  When the "bucketName" field is unset, the default bucket name "fs" is used instead.
  When the "chunkSizeBytes" field is unset, the default chunk size of 255 KiB is used instead.

See also
  - GridFS (MongoDB Manual)

## has_collection()

bool mongocxx::v1::database::has_collection | ( | bsoncxx::v1::stdx::string_view | name | ) |

Return true when this database contains a collection with the given name.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

## list_collection_names() [1/2]

std::vector< std::string > mongocxx::v1::database::list_collection_names | ( | bsoncxx::v1::document::view | filter = {} | ) |

Return an unsorted list of the names of all the collections and views in this database.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - listCollections (database command) (MongoDB Manual)

## list_collection_names() [2/2]

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

Return an unsorted list of the names of all the collections and views in this database.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - listCollections (database command) (MongoDB Manual)

## list_collections() [1/2]

v1::cursor mongocxx::v1::database::list_collections | ( | bsoncxx::v1::document::view | filter = {} | ) |

Return an unsorted list of all collections and views in this database.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - listCollections (database command) (MongoDB Manual)

## list_collections() [2/2]

v1::cursor mongocxx::v1::database::list_collections | ( | v1::client_session const & | session,
|  | bsoncxx::v1::document::view | filter = {} )

Return an unsorted list of all collections and views in this database.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - listCollections (database command) (MongoDB Manual)

## name()

bsoncxx::v1::stdx::string_view mongocxx::v1::database::name | ( |  | ) | const

Return the name of this database.

## operator bool()

mongocxx::v1::database::operator bool | ( |  | ) | const

explicit

Return true when *this is NOT in an assign-or-destroy-only state.

## operator=() [1/2]

database & mongocxx::v1::database::operator= | ( | database && | other | ) |

noexcept

Move assignment.

Postconditions:
  - other is in an assign-or-destroy-only state.

## operator=() [2/2]

database & mongocxx::v1::database::operator= | ( | database const & | other | ) |

Copy assignment.

## operator[]()

v1::collection mongocxx::v1::database::operator[] | ( | bsoncxx::v1::stdx::string_view | name | ) | const

Equivalent to this->collection(name).

## read_concern() [1/2]

v1::read_concern mongocxx::v1::database::read_concern | ( |  | ) | const

Return the current default "readConcern" to use for operations on this database.

## read_concern() [2/2]

void mongocxx::v1::database::read_concern | ( | v1::read_concern const & | rc | ) |

Set the default "readConcern" to use for operations on this database.

Overrides the default inherited from the associated client. May be overridden by individual operations.

See also
  - Default MongoDB Read Concerns/Write Concerns (MongoDB Manual)

## read_preference() [1/2]

v1::read_preference mongocxx::v1::database::read_preference | ( |  | ) | const

Return the current default "readPreference" to use for operations on this database.

## read_preference() [2/2]

void mongocxx::v1::database::read_preference | ( | v1::read_preference const & | rp | ) |

Set the default "readPreference" to use for operations on this database.

Overrides the default inherited from the associated client. May be overridden by individual operations.

See also
  - Default MongoDB Read Concerns/Write Concerns (MongoDB Manual)

## run_command() [1/3]

bsoncxx::v1::document::value mongocxx::v1::database::run_command | ( | bsoncxx::v1::document::view | command | ) |

Run an arbitrary database command.

Returns
  The raw server response.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - Database Commands

## run_command() [2/3]

bsoncxx::v1::document::value mongocxx::v1::database::run_command | ( | bsoncxx::v1::document::view | command,
|  | std::uint32_t | server_id )

Run an arbitrary database command against the requested specific server.

Returns
  The raw server response.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - Database Commands

## run_command() [3/3]

bsoncxx::v1::document::value mongocxx::v1::database::run_command | ( | v1::client_session const & | session,
|  | bsoncxx::v1::document::view | command )

Run an arbitrary database command.

Returns
  The raw server response.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - Database Commands

## watch() [1/4]

v1::change_stream mongocxx::v1::database::watch | ( | v1::change_stream::options const & | opts = {} | ) |

Return a change stream subscribed to this database.

See also
  - Change Streams (MongoDB Manual)

## watch() [2/4]

v1::change_stream mongocxx::v1::database::watch | ( | v1::client_session const & | session,
|  | v1::change_stream::options const & | opts = {} )

Return a change stream subscribed to this database.

See also
  - Change Streams (MongoDB Manual)

## watch() [3/4]

v1::change_stream mongocxx::v1::database::watch | ( | v1::client_session const & | session,
|  | v1::pipeline const & | pipeline,
|  | v1::change_stream::options const & | opts = {} )

Return a change stream subscribed to this collection with events filtered/modified by pipeline.

See also
  - Change Streams (MongoDB Manual)

## watch() [4/4]

v1::change_stream mongocxx::v1::database::watch | ( | v1::pipeline const & | pipeline,
|  | v1::change_stream::options const & | opts = {} )

Return a change stream subscribed to this collection with events filtered/modified by pipeline.

See also
  - Change Streams (MongoDB Manual)

## write_concern() [1/2]

v1::write_concern mongocxx::v1::database::write_concern | ( |  | ) | const

Return the current default "writeConcern" to use for operations on this database.

## write_concern() [2/2]

void mongocxx::v1::database::write_concern | ( | v1::write_concern const & | wc | ) |

Set the default "writeConcern" to use for operations on this database.

Overrides the default inherited from the associated client. May be overridden by individual operations.

See also
  - Default MongoDB Read Concerns/Write Concerns (MongoDB Manual)

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

- mongocxx/v1/database.hpp