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

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

## Description

A connection to a MongoDB deployment.

Important
  This interface does NOT fully conform to the CMAP specification!

See also
  - Connection Monitoring and Pooling (MongoDB Specifications)
  - Connection Strings (MongoDB Manual)

## Classes

class | options
| Options for mongocxx::v1::client. More...

## Public Types

enum class | errc
| Errors codes which may be returned by mongocxx::v1::client. More...

## Public Member Functions

| client ()
| Default initialization.
| client (client &&other) noexcept
| Move constructor.
| client (client const &other)=delete
| This class is not copyable.
| ~client ()
| Destroy this object.
v1::database | database (bsoncxx::v1::stdx::string_view name)
| Access the database with the given name.
| operator bool () const
| Return true when *this is NOT in an assign-or-destroy-only state.
client & | operator= (client &&other) noexcept
| Move assignment.
client & | operator= (client const &other)=delete
| This class is not copyable.
v1::database | operator[] (bsoncxx::v1::stdx::string_view name)
| Equivalent to this->database(name).
void | reset ()
| Invalidate this client object without invaliding existing cursors or sessions.
v1::uri | uri () const
| Return the mongocxx::v1::uri used to initialize this client.
| client (v1::uri uri, options opts)
| Initialize with the given URI.
| client (v1::uri uri)
| Initialize with the given URI.
v1::cursor | list_databases ()
| Return an unsorted list of all existing databases.
v1::cursor | list_databases (v1::client_session const &session)
| Return an unsorted list of all existing databases.
v1::cursor | list_databases (bsoncxx::v1::document::view opts)
| Return an unsorted list of all existing databases.
v1::cursor | list_databases (v1::client_session const &session, bsoncxx::v1::document::view opts)
| Return an unsorted list of all existing databases.
std::vector< std::string > | list_database_names (bsoncxx::v1::document::view filter)
| Return an unsorted list of the names of all existing databases.
std::vector< std::string > | list_database_names (v1::client_session const &session, bsoncxx::v1::document::view filter)
| Return an unsorted list of the names of all existing databases.
std::vector< std::string > | list_database_names ()
| Return an unsorted list of the names of all existing databases.
std::vector< std::string > | list_database_names (v1::client_session const &session)
| Return an unsorted list of the names of all existing databases.
v1::client_session | start_session (v1::client_session::options const &opts)
| Create a new client session to use with subsequent operations.
v1::client_session | start_session ()
| Create a new client session to use with subsequent operations.
v1::change_stream | watch (v1::change_stream::options const &opts)
| Return a change stream subscribed to this connection.
v1::change_stream | watch ()
| Return a change stream subscribed to this connection.
v1::change_stream | watch (v1::client_session const &session, v1::change_stream::options const &opts)
| Return a change stream subscribed to this connection.
v1::change_stream | watch (v1::client_session const &session)
| Return a change stream subscribed to this connection.
v1::change_stream | watch (v1::pipeline const &pipeline, v1::change_stream::options const &opts)
| Return a change stream subscribed to this connection 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 connection with events filtered/modified by pipeline.
v1::change_stream | watch (v1::pipeline const &pipeline)
| Return a change stream subscribed to this connection with events filtered/modified by pipeline.
v1::change_stream | watch (v1::client_session const &session, v1::pipeline const &pipeline)
| Return a change stream subscribed to this connection with events filtered/modified by pipeline.
v1::client_bulk_write | create_bulk_write ()
| Return a new client-level bulk write operation for use with this client.
v1::client_bulk_write | create_bulk_write (v1::client_session &session)
| Return a new client-level bulk write operation for use with this client.

## Static Public Member Functions

static std::error_category const & | error_category ()
| The error category for mongocxx::v1::client::errc.

## Friends

std::error_code | make_error_code (errc v)
| Support implicit conversion to std::error_code.

## Member Enumeration Documentation

## errc

enum class mongocxx::v1::client::errc

strong

Errors codes which may be returned by mongocxx::v1::client.

Enumerator
zero | Zero.
tls_not_enabled | TLS is not enabled by URI options.
tls_not_supported | TLS is not supported by the mongoc library.

## Constructor & Destructor Documentation

## ~client()

mongocxx::v1::client::~client | ( |  | ) |

Destroy this object.

Warning
  Invalidates all associated views, databases, cursors, client sessions, and change streams.

## client() [1/5]

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

noexcept

Move constructor.

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

## client() [2/5]

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

delete

This class is not copyable.

## client() [3/5]

mongocxx::v1::client::client | ( | v1::uri | uri,
|  | options | opts )

Initialize with the given URI.

Note
  No connection is attempted until the first command executed with this client object or with an associated object obtained from this client object. Server-side errors will only be encountered during or after the first command executed.

Exceptions

  mongocxx::v1::exception | when a client-side error is encountered.

## client() [4/5]

mongocxx::v1::client::client | ( | v1::uri | uri | ) |

Initialize with the given URI.

Note
  No connection is attempted until the first command executed with this client object or with an associated object obtained from this client object. Server-side errors will only be encountered during or after the first command executed.

Exceptions

  mongocxx::v1::exception | when a client-side error is encountered.

## client() [5/5]

mongocxx::v1::client::client | ( |  | ) |

Default initialization.

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

## Member Function Documentation

## create_bulk_write() [1/2]

v1::client_bulk_write mongocxx::v1::client::create_bulk_write | ( |  | ) |

Return a new client-level bulk write operation for use with this client.

## create_bulk_write() [2/2]

v1::client_bulk_write mongocxx::v1::client::create_bulk_write | ( | v1::client_session & | session | ) |

Return a new client-level bulk write operation for use with this client.

## database()

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

Access the database with the given name.

## error_category()

std::error_category const & mongocxx::v1::client::error_category | ( |  | ) |

static

The error category for mongocxx::v1::client::errc.

## list_database_names() [1/4]

std::vector< std::string > mongocxx::v1::client::list_database_names | ( |  | ) |

Return an unsorted list of the names of all existing databases.

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
  - listDatabases (database command) (MongoDB Manual)

## list_database_names() [2/4]

std::vector< std::string > mongocxx::v1::client::list_database_names | ( | bsoncxx::v1::document::view | filter | ) |

Return an unsorted list of the names of all existing databases.

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
  - listDatabases (database command) (MongoDB Manual)

## list_database_names() [3/4]

std::vector< std::string > mongocxx::v1::client::list_database_names | ( | v1::client_session const & | session | ) |

Return an unsorted list of the names of all existing databases.

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
  - listDatabases (database command) (MongoDB Manual)

## list_database_names() [4/4]

std::vector< std::string > mongocxx::v1::client::list_database_names | ( | v1::client_session const & | session,
|  | bsoncxx::v1::document::view | filter )

Return an unsorted list of the names of all existing databases.

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
  - listDatabases (database command) (MongoDB Manual)

## list_databases() [1/4]

v1::cursor mongocxx::v1::client::list_databases | ( |  | ) |

Return an unsorted list of all existing databases.

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
  - listDatabases (database command) (MongoDB Manual)

## list_databases() [2/4]

v1::cursor mongocxx::v1::client::list_databases | ( | bsoncxx::v1::document::view | opts | ) |

Return an unsorted list of all existing databases.

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
  - listDatabases (database command) (MongoDB Manual)

## list_databases() [3/4]

v1::cursor mongocxx::v1::client::list_databases | ( | v1::client_session const & | session | ) |

Return an unsorted list of all existing databases.

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
  - listDatabases (database command) (MongoDB Manual)

## list_databases() [4/4]

v1::cursor mongocxx::v1::client::list_databases | ( | v1::client_session const & | session,
|  | bsoncxx::v1::document::view | opts )

Return an unsorted list of all existing databases.

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
  - listDatabases (database command) (MongoDB Manual)

## operator bool()

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

explicit

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

## operator=() [1/2]

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

noexcept

Move assignment.

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

## operator=() [2/2]

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

delete

This class is not copyable.

## operator[]()

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

Equivalent to this->database(name).

## reset()

void mongocxx::v1::client::reset | ( |  | ) |

Invalidate this client object without invaliding existing cursors or sessions.

Warning
  Do not call this member function on a client obtained from a v1::pool.

This function must be invoked by a (forked) child process to prevent its destruction within the child process from invalidating the state of the client object within the parent process.

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

See also
  - mongoc_client_reset

## start_session() [1/2]

v1::client_session mongocxx::v1::client::start_session | ( |  | ) |

Create a new client session to use with subsequent operations.

Important
  The client session object MUST be passed as the first argument to all operations that are intended to be executed in the context of a session.

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
  - Server Sessions (MongoDB Manual)

## start_session() [2/2]

v1::client_session mongocxx::v1::client::start_session | ( | v1::client_session::options const & | opts | ) |

Create a new client session to use with subsequent operations.

Important
  The client session object MUST be passed as the first argument to all operations that are intended to be executed in the context of a session.

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
  - Server Sessions (MongoDB Manual)

## uri()

v1::uri mongocxx::v1::client::uri | ( |  | ) | const

Return the mongocxx::v1::uri used to initialize this client.

## watch() [1/8]

v1::change_stream mongocxx::v1::client::watch | ( |  | ) |

Return a change stream subscribed to this connection.

See also
  - Change Streams (MongoDB Manual)

## watch() [2/8]

v1::change_stream mongocxx::v1::client::watch | ( | v1::change_stream::options const & | opts | ) |

Return a change stream subscribed to this connection.

See also
  - Change Streams (MongoDB Manual)

## watch() [3/8]

v1::change_stream mongocxx::v1::client::watch | ( | v1::client_session const & | session | ) |

Return a change stream subscribed to this connection.

See also
  - Change Streams (MongoDB Manual)

## watch() [4/8]

v1::change_stream mongocxx::v1::client::watch | ( | v1::client_session const & | session,
|  | v1::change_stream::options const & | opts )

Return a change stream subscribed to this connection.

See also
  - Change Streams (MongoDB Manual)

## watch() [5/8]

v1::change_stream mongocxx::v1::client::watch | ( | v1::client_session const & | session,
|  | v1::pipeline const & | pipeline )

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

See also
  - Change Streams (MongoDB Manual)

## watch() [6/8]

v1::change_stream mongocxx::v1::client::watch | ( | v1::client_session const & | session,
|  | v1::pipeline const & | pipeline,
|  | v1::change_stream::options const & | opts )

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

See also
  - Change Streams (MongoDB Manual)

## watch() [7/8]

v1::change_stream mongocxx::v1::client::watch | ( | v1::pipeline const & | pipeline | ) |

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

See also
  - Change Streams (MongoDB Manual)

## watch() [8/8]

v1::change_stream mongocxx::v1::client::watch | ( | v1::pipeline const & | pipeline,
|  | v1::change_stream::options const & | opts )

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

See also
  - Change Streams (MongoDB Manual)

## Friends And Related Symbol Documentation

## make_error_code

std::error_code make_error_code | ( | errc | v | ) |

friend

Support implicit conversion to std::error_code.

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

- mongocxx/v1/client.hpp