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

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

## Description

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 (database &&other) noexcept=default
| Move constructs a database.
| database (database const &other)
| Copy constructs a database.
| database (v1::database database)
| Construct with the mongocxx::v1 equivalent.
| ~database ()=default
| Destroys a database.
v_noabi::cursor | aggregate (v_noabi::client_session const &session, v_noabi::pipeline const &pipeline, v_noabi::options::aggregate const &options={})
| Runs an aggregation framework pipeline against this database for pipeline stages that do not require an underlying collection, such as $currentOp and $listLocalSessions.
v_noabi::cursor | aggregate (v_noabi::pipeline const &pipeline, v_noabi::options::aggregate const &options={})
| Runs an aggregation framework pipeline against this database for pipeline stages that do not require an underlying collection, such as $currentOp and $listLocalSessions.
v_noabi::collection | collection (bsoncxx::v_noabi::string::view_or_value name) const
| Access a collection (logical grouping of documents) within this database.
v_noabi::collection | create_collection (bsoncxx::v_noabi::stdx::string_view name, bsoncxx::v_noabi::document::view_or_value collection_options={}, bsoncxx::v_noabi::stdx::optional< v_noabi::write_concern > const &write_concern={})
| Explicitly creates a collection in this database with the specified options.
v_noabi::collection | create_collection (v_noabi::client_session const &session, bsoncxx::v_noabi::stdx::string_view name, bsoncxx::v_noabi::document::view_or_value collection_options={}, bsoncxx::v_noabi::stdx::optional< v_noabi::write_concern > const &write_concern={})
| Explicitly creates a collection in this database with the specified options.
void | drop (bsoncxx::v_noabi::stdx::optional< v_noabi::write_concern > const &write_concern={})
| Drops the database and all its collections.
void | drop (v_noabi::client_session const &session, bsoncxx::v_noabi::stdx::optional< v_noabi::write_concern > const &write_concern={})
| Drops the database and all its collections.
v_noabi::gridfs::bucket | gridfs_bucket (v_noabi::options::gridfs::bucket const &options={}) 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 (v_noabi::client_session const &session, bsoncxx::v_noabi::document::view_or_value filter={})
| Enumerates the collection names in this database.
v_noabi::cursor | list_collections (bsoncxx::v_noabi::document::view_or_value filter={})
| Enumerates the collections in this database.
v_noabi::cursor | list_collections (v_noabi::client_session const &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.
| operator v1::database () &&
| Convert to the mongocxx::v1 equivalent.
| operator v1::database () const &
| Convert to the mongocxx::v1 equivalent.
database & | operator= (database &&other) noexcept=default
| Move assigns a database.
database & | operator= (database const &other)
| Copy assigns a database.
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.
v_noabi::read_concern | read_concern () const
| The current read concern for this database.
void | read_concern (v_noabi::read_concern rc)
| Sets the read_concern for this database.
v_noabi::read_preference | read_preference () const
| The current read preference for this database.
void | read_preference (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, std::uint32_t server_id)
| Executes a command on a specific server using this database.
bsoncxx::v_noabi::document::value | run_command (v_noabi::client_session const &session, bsoncxx::v_noabi::document::view_or_value command)
| Runs a command against this database.
v_noabi::change_stream | watch (v_noabi::client_session const &session, v_noabi::options::change_stream const &options={})
v_noabi::change_stream | watch (v_noabi::client_session const &session, v_noabi::pipeline const &pipe, v_noabi::options::change_stream const &options={})
| Gets a change stream on this database.
v_noabi::change_stream | watch (v_noabi::options::change_stream const &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.
v_noabi::change_stream | watch (v_noabi::pipeline const &pipe, v_noabi::options::change_stream const &options={})
| Gets a change stream on this database. Change streams are only supported with a "majority" read concern or no read concern.
v_noabi::write_concern | write_concern () const
| The current write_concern for this database.
void | write_concern (v_noabi::write_concern wc)
| Sets the write_concern for this database.

## Constructor & Destructor Documentation

## database() [1/4]

mongocxx::v_noabi::database::database | ( |  | ) |

inline 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/4]

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

default noexcept

Move constructs a database.

## database() [3/4]

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

Copy constructs a database.

## ~database()

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

default

Destroys a database.

## database() [4/4]

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

inline

Construct with the mongocxx::v1 equivalent.

## Member Function Documentation

## aggregate() [1/2]

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

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

Parameters

  session | The mongocxx::v_noabi::client_session with which to perform the aggregation.
  pipeline | The pipeline of aggregation operations to perform.
  options | Optional 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
  - https://www.mongodb.com/docs/manual/reference/command/aggregate/#dbcmd.aggregate

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]

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

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

Parameters

  pipeline | The pipeline of aggregation operations to perform.
  options | Optional 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
  - https://www.mongodb.com/docs/manual/reference/command/aggregate/#dbcmd.aggregate

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()

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

  name | the name of the collection to get.

Returns
  the collection.

## create_collection() [1/2]

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 = {},
|  | bsoncxx::v_noabi::stdx::optional< v_noabi::write_concern > const & | write_concern = {} )

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

See also
  - https://www.mongodb.com/docs/manual/reference/command/create/

Note
  This function can also be used to create a Time Series Collection. See: https://www.mongodb.com/docs/manual/core/timeseries-collections/

Parameters

  name | the new collection's name.
  collection_options | the options for the new collection.
  write_concern | the write concern to use for this operation. Will default to database set write concern if none passed here.

Exceptions

  mongocxx::v_noabi::operation_exception | if the operation fails.

## create_collection() [2/2]

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

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

See also
  - https://www.mongodb.com/docs/manual/reference/command/create/

Note
  This function can also be used to create a Time Series Collection. See: https://www.mongodb.com/docs/manual/core/timeseries-collections/

Parameters

  session | The mongocxx::v_noabi::client_session with which to perform the create operation.
  name | the new collection's name.
  collection_options | the options for the new collection.
  write_concern | the write concern to use for this operation. Will default to database set write concern if none passed here.

Exceptions

  mongocxx::v_noabi::operation_exception | if the operation fails.

## drop() [1/2]

void mongocxx::v_noabi::database::drop | ( | bsoncxx::v_noabi::stdx::optional< v_noabi::write_concern > const & | 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_exception | if the operation fails.

See also
  - https://www.mongodb.com/docs/manual/reference/command/dropDatabase/

## drop() [2/2]

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

Drops the database and all its collections.

Parameters

  session | The 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_exception | if the operation fails.

See also
  - https://www.mongodb.com/docs/manual/reference/command/dropDatabase/

## gridfs_bucket()

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

Access a GridFS bucket within this database.

Parameters

  options | The 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_error | if 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

  name | the name of the collection.

Returns
  bool whether the collection exists in this database.

Exceptions

  mongocxx::v_noabi::operation_exception | if 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

  filter | An optional query expression to filter the returned collection names.

Returns
  std::vector<std::string> containing the collection names.

Exceptions

  mongocxx::v_noabi::operation_exception | if the underlying 'listCollections' command fails.

See also
  - https://www.mongodb.com/docs/manual/reference/command/listCollections/

## list_collection_names() [2/2]

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

Enumerates the collection names in this database.

Parameters

  session | The mongocxx::v_noabi::client_session with which to perform the aggregation.
  filter | An optional query expression to filter the returned collection names.

Returns
  std::vector<std::string> containing the collection names.

Exceptions

  mongocxx::v_noabi::operation_exception | if the underlying 'listCollections' command fails.

See also
  - https://www.mongodb.com/docs/manual/reference/command/listCollections/

## list_collections() [1/2]

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

Enumerates the collections in this database.

Parameters

  filter | An optional query expression to filter the returned collections.

Returns
  mongocxx::v_noabi::cursor containing the collection information.

See also
  - https://www.mongodb.com/docs/manual/reference/command/listCollections/

## list_collections() [2/2]

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

Enumerates the collections in this database.

Parameters

  session | The mongocxx::v_noabi::client_session with which to perform the aggregation.
  filter | An optional query expression to filter the returned collections.

Returns
  mongocxx::v_noabi::cursor containing the collection information.

See also
  - https://www.mongodb.com/docs/manual/reference/command/listCollections/

## 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

inline explicit noexcept

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

## operator v1::database() [1/2]

mongocxx::v_noabi::database::operator v1::database | ( |  | ) | &&

inline explicit

Convert to the mongocxx::v1 equivalent.

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

Warning
  Invalidates all associated objects.

## operator v1::database() [2/2]

mongocxx::v_noabi::database::operator v1::database | ( |  | ) | const &

inline explicit

Convert to the mongocxx::v1 equivalent.

## operator=() [1/2]

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

default noexcept

Move assigns a database.

## operator=() [2/2]

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

Copy assigns a database.

## operator[]()

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

  name | the name of the collection to get.

Returns
  the collection.

## read_concern() [1/2]

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 | ( | 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

  rc | The new `read_concern`

See also
  - https://www.mongodb.com/docs/manual/reference/read-concern/

## read_preference() [1/2]

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

The current read preference for this database.

See also
  - https://www.mongodb.com/docs/manual/core/read-preference/

Returns
  the current read_preference

## read_preference() [2/2]

void mongocxx::v_noabi::database::read_preference | ( | 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
  - https://www.mongodb.com/docs/manual/core/read-preference/

Parameters

  rp | the 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
  - https://www.mongodb.com/docs/manual/reference/method/db.runCommand/

Parameters

  command | document representing the command to be run.

Returns
  the result of executing the command.

Exceptions

  mongocxx::v_noabi::operation_exception | if 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,
|  | std::uint32_t | server_id )

Executes a command on a specific server using this database.

See also
  - https://www.mongodb.com/docs/manual/reference/method/db.runCommand/

Parameters

  command | document representing the command to be run.
  server_id | specifying which server to use.

Returns
  the result of executing the command.

Exceptions

  mongocxx::v_noabi::operation_exception | if the operation fails.

## run_command() [3/3]

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

Runs a command against this database.

See also
  - https://www.mongodb.com/docs/manual/reference/method/db.runCommand/

Parameters

  session | The mongocxx::v_noabi::client_session with which to run the command.
  command | document representing the command to be run.

Returns
  the result of executing the command.

Exceptions

  mongocxx::v_noabi::operation_exception | if the operation fails.

## watch() [1/4]

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

Parameters

  session | The mongocxx::v_noabi::client_session with which to perform the watch operation.
  options | The options to use when creating the change stream.

Returns
  A change stream on this database.

See also
  - https://www.mongodb.com/docs/manual/changeStreams/

## watch() [2/4]

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

Gets a change stream on this database.

Parameters

  session | The mongocxx::v_noabi::client_session with which to perform the watch operation.
  pipe | The aggregation pipeline to be used on the change notifications.
  options | The options to use when creating the change stream.

Returns
  A change stream on this database.

See also
  - https://www.mongodb.com/docs/manual/changeStreams/

## watch() [3/4]

v_noabi::change_stream mongocxx::v_noabi::database::watch | ( | v_noabi::options::change_stream const & | 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

  options | The options to use when creating the change stream.

Returns
  A change stream on this database.

See also
  - https://www.mongodb.com/docs/manual/changeStreams/

## watch() [4/4]

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

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

Parameters

  pipe | The 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.
  options | The options to use when creating the change stream.

Returns
  A change stream on this database.

See also
  - https://www.mongodb.com/docs/manual/changeStreams/

## write_concern() [1/2]

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 | ( | 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:

- mongocxx/v_noabi/mongocxx/database.hpp