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

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

## Description

A MongoDB connection string.

Supported fields include:

- appname ("appName")
- auth_mechanism_properties ("authMechanismProperties")
- auth_mechanism ("authMechanism")
- auth_source ("authSource")
- compressors
- connect_timeout_ms ("connectTimeoutMS")
- database
- direct_connection ("directConnection")
- enable_overload_retargeting ("enableOverloadRetargeting")
- heartbeat_frequency_ms ("heartbeatFrequencyMS")
- hosts
- local_threshold_ms ("localThresholdMS")
- max_pool_size ("maxPoolSize")
- max_adaptive_retries ("maxAdaptiveRetries")
- password
- read_concern ("readConcern")
- read_preference ("readPreference")
- replica_set ("replicaSet")
- retry_reads ("retryReads")
- retry_writes ("retryWrites")
- server_selection_timeout_ms ("serverSelectionTimeoutMS")
- server_selection_try_once ("serverSelectionTryOnce")
- socket_timeout_ms ("socketTimeoutMS")
- srv_max_hosts ("srvMaxHosts")
- tls_allow_invalid_certificates ("tlsAllowInvalidCertificates")
- tls_allow_invalid_hostnames ("tlsAllowInvalidHostnames")
- tls_ca_file ("tlsCAFile")
- tls_certificate_key_file_password ("tlsCertificateKeyFilePassword")
- tls_certificate_key_file ("tlsCertificateKeyFile")
- tls_disable_certificate_revocation_check
- tls_disable_ocsp_endpoint_check
- tls_insecure ("tlsInsecure")
- tls
- username
- wait_queue_timeout_ms ("waitQueueTimeoutMS")
- write_concern ("writeConcern")
- zlib_compression_level ("zlibCompressionLevel")

See also
  - Connection Strings (MongoDB Manual)

## Classes

struct | host
| A host identifier. More...

## Public Types

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

## Public Member Functions

| uri ()
| Equivalent to uri(bsoncxx::v1::stdx::string_view v) with k_default_uri.
| uri (bsoncxx::v1::stdx::string_view v)
| Initialize with the given connection string.
| uri (uri &&other) noexcept
| Move constructor.
| uri (uri const &other)
| Copy construction.
| ~uri ()
| Destroy this object.
bsoncxx::v1::stdx::optional< bsoncxx::v1::stdx::string_view > | appname () const
| Return the "appName" option.
bsoncxx::v1::stdx::string_view | auth_mechanism () const
| Return the "authMechanism" option.
bsoncxx::v1::stdx::optional< bsoncxx::v1::document::view > | auth_mechanism_properties () const
| Return the "authMechanismProperties" option.
bsoncxx::v1::stdx::string_view | auth_source () const
| Return the "authSource" option.
std::vector< bsoncxx::v1::stdx::string_view > | compressors () const
| Return the "compressors" option.
bsoncxx::v1::stdx::optional< std::int32_t > | connect_timeout_ms () const
| Return the "connectTimeoutMS" option.
bsoncxx::v1::stdx::optional< bsoncxx::v1::document::view > | credentials () const
| Return the mongoc "credentials" field containing "authMechanism" and related options.
bsoncxx::v1::stdx::string_view | database () const
| Return the database name specified by the connection string.
bsoncxx::v1::stdx::optional< bool > | direct_connection () const
| Return the "directConnection" option.
bsoncxx::v1::stdx::optional< bool > | enable_overload_retargeting () const
| Return the "enableOverloadRetargeting" option.
bsoncxx::v1::stdx::optional< std::int32_t > | heartbeat_frequency_ms () const
| Return the "heartbeatFrequencyMS" option.
std::vector< host > | hosts () const
| Return the host(s) identifiers specified by the connection string.
bsoncxx::v1::stdx::optional< std::int32_t > | local_threshold_ms () const
| Return the "localThresholdMS" option.
bsoncxx::v1::stdx::optional< std::int32_t > | max_adaptive_retries () const
| Return the "maxAdaptiveRetries" option.
bsoncxx::v1::stdx::optional< std::int32_t > | max_pool_size () const
| Return the "maxPoolSize" option.
uri & | operator= (uri &&other) noexcept
| Move assignment.
uri & | operator= (uri const &other)
| Copy assignment.
bsoncxx::v1::document::view | options () const
| Return all URI options that were specified by the connection string.
bsoncxx::v1::stdx::string_view | password () const
| Return the password specified by the connection string.
v1::read_concern | read_concern () const
| Return the "readConcern" option.
v1::read_preference | read_preference () const
| Return the "readPreference" option.
bsoncxx::v1::stdx::string_view | replica_set () const
| Return the "replicaSet" option.
bsoncxx::v1::stdx::optional< bool > | retry_reads () const
| Return the "retryReads" option.
bsoncxx::v1::stdx::optional< bool > | retry_writes () const
| Return the "retryWrites" option.
bsoncxx::v1::stdx::optional< std::int32_t > | server_selection_timeout_ms () const
| Return the "serverSelectionTimeoutMS" option.
bsoncxx::v1::stdx::optional< bool > | server_selection_try_once () const
| Return the "serverSelectionTryOnce" option.
uri & | server_selection_try_once (bool val)
| Set the "serverSelectionTryOnce" option.
bsoncxx::v1::stdx::optional< std::int32_t > | socket_timeout_ms () const
| Return the "socketTimeoutMS" option.
bsoncxx::v1::stdx::optional< std::int32_t > | srv_max_hosts () const
| Return the "srvMaxHosts" option.
bool | tls () const
| Return the "tls" option.
bsoncxx::v1::stdx::optional< bool > | tls_allow_invalid_certificates () const
| Return the "tlsAllowInvalidCertificates" option.
bsoncxx::v1::stdx::optional< bool > | tls_allow_invalid_hostnames () const
| Return the "tlsAllowInvalidHostnames" option.
bsoncxx::v1::stdx::optional< bsoncxx::v1::stdx::string_view > | tls_ca_file () const
| Return the "tlsCAFile" option.
bsoncxx::v1::stdx::optional< bsoncxx::v1::stdx::string_view > | tls_certificate_key_file () const
| Return the "tlsCertificateKeyFile" option.
bsoncxx::v1::stdx::optional< bsoncxx::v1::stdx::string_view > | tls_certificate_key_file_password () const
| Return the "tlsCertificateKeyFilePassword" option.
bsoncxx::v1::stdx::optional< bool > | tls_disable_certificate_revocation_check () const
| Return the (mongoc-specific) "tlsDisableCertificateRevocationCheck" option.
bsoncxx::v1::stdx::optional< bool > | tls_disable_ocsp_endpoint_check () const
| Return the (mongoc-specific) "tlsDisableOCSPEndpointCheck" option.
bsoncxx::v1::stdx::optional< bool > | tls_insecure () const
| Return the "tlsInsecure" option.
bsoncxx::v1::stdx::string_view | to_string () const
| Return this URI as a connection string.
bsoncxx::v1::stdx::string_view | username () const
| Return the username specified by the connection string.
bsoncxx::v1::stdx::optional< std::int32_t > | wait_queue_timeout_ms () const
| Return the "waitQueueTimeoutMS" option.
v1::write_concern | write_concern () const
| Return the "writeConcern" option.
bsoncxx::v1::stdx::optional< std::int32_t > | zlib_compression_level () const
| Return the "zlibCompressionLevel" option.

## Static Public Member Functions

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

## Static Public Attributes

static constexpr auto | k_default_uri = "mongodb://localhost:27017"
| The default connection string.

## Friends

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

## Member Enumeration Documentation

## errc

enum class mongocxx::v1::uri::errc

strong

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

Enumerator
zero | Zero.
set_failure | Failed to set the requested URI option.

## Constructor & Destructor Documentation

## ~uri()

mongocxx::v1::uri::~uri | ( |  | ) |

Destroy this object.

Warning
  Invalidates all associated views.

## uri() [1/4]

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

noexcept

Move constructor.

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

## uri() [2/4]

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

Copy construction.

## uri() [3/4]

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

Equivalent to uri(bsoncxx::v1::stdx::string_view v) with k_default_uri.

## uri() [4/4]

mongocxx::v1::uri::uri | ( | bsoncxx::v1::stdx::string_view | v | ) |

Initialize with the given connection string.

Postconditions:
  - All supported options specified by the connection string are set accordingly.
  - this->options() returns a document containing all options specified by the connection string.
  - All other supported options are "unset" or zero-initialized.

Exceptions

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

## Member Function Documentation

## appname()

bsoncxx::v1::stdx::optional< bsoncxx::v1::stdx::string_view > mongocxx::v1::uri::appname | ( |  | ) | const

Return the "appName" option.

## auth_mechanism()

bsoncxx::v1::stdx::string_view mongocxx::v1::uri::auth_mechanism | ( |  | ) | const

Return the "authMechanism" option.

## auth_mechanism_properties()

bsoncxx::v1::stdx::optional< bsoncxx::v1::document::view > mongocxx::v1::uri::auth_mechanism_properties | ( |  | ) | const

Return the "authMechanismProperties" option.

## auth_source()

bsoncxx::v1::stdx::string_view mongocxx::v1::uri::auth_source | ( |  | ) | const

Return the "authSource" option.

## compressors()

std::vector< bsoncxx::v1::stdx::string_view > mongocxx::v1::uri::compressors | ( |  | ) | const

Return the "compressors" option.

## connect_timeout_ms()

bsoncxx::v1::stdx::optional< std::int32_t > mongocxx::v1::uri::connect_timeout_ms | ( |  | ) | const

Return the "connectTimeoutMS" option.

## credentials()

bsoncxx::v1::stdx::optional< bsoncxx::v1::document::view > mongocxx::v1::uri::credentials | ( |  | ) | const

Return the mongoc "credentials" field containing "authMechanism" and related options.

## database()

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

Return the database name specified by the connection string.

Returns
  Empty when no database name was specified.

## direct_connection()

bsoncxx::v1::stdx::optional< bool > mongocxx::v1::uri::direct_connection | ( |  | ) | const

Return the "directConnection" option.

## enable_overload_retargeting()

bsoncxx::v1::stdx::optional< bool > mongocxx::v1::uri::enable_overload_retargeting | ( |  | ) | const

Return the "enableOverloadRetargeting" option.

## error_category()

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

static

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

## heartbeat_frequency_ms()

bsoncxx::v1::stdx::optional< std::int32_t > mongocxx::v1::uri::heartbeat_frequency_ms | ( |  | ) | const

Return the "heartbeatFrequencyMS" option.

## hosts()

std::vector< host > mongocxx::v1::uri::hosts | ( |  | ) | const

Return the host(s) identifiers specified by the connection string.

## local_threshold_ms()

bsoncxx::v1::stdx::optional< std::int32_t > mongocxx::v1::uri::local_threshold_ms | ( |  | ) | const

Return the "localThresholdMS" option.

## max_adaptive_retries()

bsoncxx::v1::stdx::optional< std::int32_t > mongocxx::v1::uri::max_adaptive_retries | ( |  | ) | const

Return the "maxAdaptiveRetries" option.

## max_pool_size()

bsoncxx::v1::stdx::optional< std::int32_t > mongocxx::v1::uri::max_pool_size | ( |  | ) | const

Return the "maxPoolSize" option.

## operator=() [1/2]

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

noexcept

Move assignment.

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

## operator=() [2/2]

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

Copy assignment.

## options()

bsoncxx::v1::document::view mongocxx::v1::uri::options | ( |  | ) | const

Return all URI options that were specified by the connection string.

## password()

bsoncxx::v1::stdx::string_view mongocxx::v1::uri::password | ( |  | ) | const

Return the password specified by the connection string.

## read_concern()

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

Return the "readConcern" option.

## read_preference()

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

Return the "readPreference" option.

## replica_set()

bsoncxx::v1::stdx::string_view mongocxx::v1::uri::replica_set | ( |  | ) | const

Return the "replicaSet" option.

## retry_reads()

bsoncxx::v1::stdx::optional< bool > mongocxx::v1::uri::retry_reads | ( |  | ) | const

Return the "retryReads" option.

## retry_writes()

bsoncxx::v1::stdx::optional< bool > mongocxx::v1::uri::retry_writes | ( |  | ) | const

Return the "retryWrites" option.

## server_selection_timeout_ms()

bsoncxx::v1::stdx::optional< std::int32_t > mongocxx::v1::uri::server_selection_timeout_ms | ( |  | ) | const

Return the "serverSelectionTimeoutMS" option.

## server_selection_try_once() [1/2]

bsoncxx::v1::stdx::optional< bool > mongocxx::v1::uri::server_selection_try_once | ( |  | ) | const

Return the "serverSelectionTryOnce" option.

## server_selection_try_once() [2/2]

uri & mongocxx::v1::uri::server_selection_try_once | ( | bool | val | ) |

Set the "serverSelectionTryOnce" option.

Exceptions

  mongocxx::v1::exception | with mongocxx::v1::uri::errc::set_failure if mongoc failed to set this URI option.

## socket_timeout_ms()

bsoncxx::v1::stdx::optional< std::int32_t > mongocxx::v1::uri::socket_timeout_ms | ( |  | ) | const

Return the "socketTimeoutMS" option.

## srv_max_hosts()

bsoncxx::v1::stdx::optional< std::int32_t > mongocxx::v1::uri::srv_max_hosts | ( |  | ) | const

Return the "srvMaxHosts" option.

## tls()

bool mongocxx::v1::uri::tls | ( |  | ) | const

Return the "tls" option.

## tls_allow_invalid_certificates()

bsoncxx::v1::stdx::optional< bool > mongocxx::v1::uri::tls_allow_invalid_certificates | ( |  | ) | const

Return the "tlsAllowInvalidCertificates" option.

## tls_allow_invalid_hostnames()

bsoncxx::v1::stdx::optional< bool > mongocxx::v1::uri::tls_allow_invalid_hostnames | ( |  | ) | const

Return the "tlsAllowInvalidHostnames" option.

## tls_ca_file()

bsoncxx::v1::stdx::optional< bsoncxx::v1::stdx::string_view > mongocxx::v1::uri::tls_ca_file | ( |  | ) | const

Return the "tlsCAFile" option.

## tls_certificate_key_file()

bsoncxx::v1::stdx::optional< bsoncxx::v1::stdx::string_view > mongocxx::v1::uri::tls_certificate_key_file | ( |  | ) | const

Return the "tlsCertificateKeyFile" option.

## tls_certificate_key_file_password()

bsoncxx::v1::stdx::optional< bsoncxx::v1::stdx::string_view > mongocxx::v1::uri::tls_certificate_key_file_password | ( |  | ) | const

Return the "tlsCertificateKeyFilePassword" option.

## tls_disable_certificate_revocation_check()

bsoncxx::v1::stdx::optional< bool > mongocxx::v1::uri::tls_disable_certificate_revocation_check | ( |  | ) | const

Return the (mongoc-specific) "tlsDisableCertificateRevocationCheck" option.

## tls_disable_ocsp_endpoint_check()

bsoncxx::v1::stdx::optional< bool > mongocxx::v1::uri::tls_disable_ocsp_endpoint_check | ( |  | ) | const

Return the (mongoc-specific) "tlsDisableOCSPEndpointCheck" option.

## tls_insecure()

bsoncxx::v1::stdx::optional< bool > mongocxx::v1::uri::tls_insecure | ( |  | ) | const

Return the "tlsInsecure" option.

## to_string()

bsoncxx::v1::stdx::string_view mongocxx::v1::uri::to_string | ( |  | ) | const

Return this URI as a connection string.

## username()

bsoncxx::v1::stdx::string_view mongocxx::v1::uri::username | ( |  | ) | const

Return the username specified by the connection string.

## wait_queue_timeout_ms()

bsoncxx::v1::stdx::optional< std::int32_t > mongocxx::v1::uri::wait_queue_timeout_ms | ( |  | ) | const

Return the "waitQueueTimeoutMS" option.

## write_concern()

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

Return the "writeConcern" option.

## zlib_compression_level()

bsoncxx::v1::stdx::optional< std::int32_t > mongocxx::v1::uri::zlib_compression_level | ( |  | ) | const

Return the "zlibCompressionLevel" option.

## Friends And Related Symbol Documentation

## make_error_code

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

friend

Support implicit conversion to std::error_code.

## Member Data Documentation

## k_default_uri

char const * mongocxx::v1::uri::k_default_uri = "mongodb://localhost:27017"

static constexpr

The default connection string.

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

- mongocxx/v1/uri.hpp