Loading...
Searching...
No Matches
uri.hpp
Go to the documentation of this file.
// Copyright 2009-present MongoDB, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <mongocxx/v1/uri-fwd.hpp> // IWYU pragma: export
//
#include <mongocxx/v1/detail/prelude.hpp>
#include <bsoncxx/v1/document/view-fwd.hpp>
#include <mongocxx/v1/read_concern-fwd.hpp>
#include <mongocxx/v1/read_preference-fwd.hpp>
#include <mongocxx/v1/write_concern-fwd.hpp>
#include <bsoncxx/v1/detail/macros.hpp>
#include <bsoncxx/v1/stdx/optional.hpp>
#include <bsoncxx/v1/stdx/string_view.hpp>
#include <mongocxx/v1/config/export.hpp>
#include <cstdint>
#include <string>
#include <system_error>
#include <type_traits>
#include <vector>
namespace mongocxx {
namespace v1 {
class uri {
private:
void* _impl; // mongoc_uri_t
public:
struct host {
std::string name;
std::uint16_t port;
std::int32_t family;
};
static constexpr auto k_default_uri = "mongodb://localhost:27017";
MONGOCXX_ABI_EXPORT_CDECL() ~uri();
MONGOCXX_ABI_EXPORT_CDECL() uri(uri&& other) noexcept;
MONGOCXX_ABI_EXPORT_CDECL(uri&) operator=(uri&& other) noexcept;
MONGOCXX_ABI_EXPORT_CDECL() uri(uri const& other);
MONGOCXX_ABI_EXPORT_CDECL(uri&) operator=(uri const& other);
MONGOCXX_ABI_EXPORT_CDECL() uri();
/* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() uri(bsoncxx::v1::stdx::string_view v);
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) auth_mechanism() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) auth_source() const;
MONGOCXX_ABI_EXPORT_CDECL(std::vector<host>) hosts() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) database() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) options() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) password() const;
MONGOCXX_ABI_EXPORT_CDECL(v1::read_concern) read_concern() const;
MONGOCXX_ABI_EXPORT_CDECL(v1::read_preference) read_preference() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) replica_set() const;
MONGOCXX_ABI_EXPORT_CDECL(bool) tls() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) to_string() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) username() const;
MONGOCXX_ABI_EXPORT_CDECL(v1::write_concern) write_concern() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::stdx::string_view>) appname() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view>) auth_mechanism_properties()
const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view>) credentials() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) srv_max_hosts() const;
MONGOCXX_ABI_EXPORT_CDECL(std::vector<bsoncxx::v1::stdx::string_view>) compressors() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) connect_timeout_ms() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) direct_connection() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) heartbeat_frequency_ms() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) local_threshold_ms() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) max_adaptive_retries() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) enable_overload_retargeting() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) max_pool_size() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) retry_reads() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) retry_writes() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) server_selection_timeout_ms() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) server_selection_try_once() const;
MONGOCXX_ABI_EXPORT_CDECL(uri&) server_selection_try_once(bool val);
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) socket_timeout_ms() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) tls_allow_invalid_certificates() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) tls_allow_invalid_hostnames() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::stdx::string_view>) tls_ca_file() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::stdx::string_view>) tls_certificate_key_file()
const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::stdx::string_view>)
tls_certificate_key_file_password() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) tls_disable_certificate_revocation_check() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) tls_disable_ocsp_endpoint_check() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) tls_insecure() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) wait_queue_timeout_ms() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) zlib_compression_level() const;
enum class errc {
zero,
set_failure,
};
static MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category();
friend std::error_code make_error_code(errc v) {
return {static_cast<int>(v), error_category()};
}
class internal;
private:
// MSVC may incorrectly select the `void*` ctor given a `char const*` argument without `/Zc:strictStrings`.
struct void_ptr {
void* impl = nullptr;
};
explicit uri(void_ptr vp);
};
BSONCXX_PRIVATE_INLINE_CXX17 constexpr char const* uri::k_default_uri;
} // namespace v1
} // namespace mongocxx
namespace std {
template <>
struct is_error_code_enum<mongocxx::v1::uri::errc> : true_type {};
} // namespace std
#include <mongocxx/v1/detail/postlude.hpp>
macros.hpp
For internal use only!
mongocxx::v1::uri::tls_disable_certificate_revocation_check
bsoncxx::v1::stdx::optional< bool > tls_disable_certificate_revocation_check() const
Return the (mongoc-specific) "tlsDisableCertificateRevocationCheck" option.
mongocxx::v1::uri::tls_allow_invalid_certificates
bsoncxx::v1::stdx::optional< bool > tls_allow_invalid_certificates() const
Return the "tlsAllowInvalidCertificates" option.
mongocxx::v1::uri::tls_certificate_key_file_password
bsoncxx::v1::stdx::optional< bsoncxx::v1::stdx::string_view > tls_certificate_key_file_password() const
Return the "tlsCertificateKeyFilePassword" option.
mongocxx::v1::uri::zlib_compression_level
bsoncxx::v1::stdx::optional< std::int32_t > zlib_compression_level() const
Return the "zlibCompressionLevel" option.
mongocxx::v1::uri::server_selection_try_once
bsoncxx::v1::stdx::optional< bool > server_selection_try_once() const
Return the "serverSelectionTryOnce" option.
mongocxx::v1::uri::k_default_uri
static constexpr auto k_default_uri
The default connection string.
Definition uri.hpp:106
mongocxx::v1::uri::server_selection_timeout_ms
bsoncxx::v1::stdx::optional< std::int32_t > server_selection_timeout_ms() const
Return the "serverSelectionTimeoutMS" option.
mongocxx::v1::uri::direct_connection
bsoncxx::v1::stdx::optional< bool > direct_connection() const
Return the "directConnection" option.
mongocxx::v1::uri::read_concern
v1::read_concern read_concern() const
Return the "readConcern" option.
mongocxx::v1::uri::max_pool_size
bsoncxx::v1::stdx::optional< std::int32_t > max_pool_size() const
Return the "maxPoolSize" option.
mongocxx::v1::uri::uri
uri(uri &&other) noexcept
Move constructor.
mongocxx::v1::uri::errc
errc
Errors codes which may be returned by mongocxx::v1::uri.
Definition uri.hpp:374
mongocxx::v1::uri::errc::set_failure
@ set_failure
Failed to set the requested URI option.
Definition uri.hpp:376
mongocxx::v1::uri::errc::zero
@ zero
Zero.
Definition uri.hpp:375
mongocxx::v1::uri::retry_reads
bsoncxx::v1::stdx::optional< bool > retry_reads() const
Return the "retryReads" option.
mongocxx::v1::uri::enable_overload_retargeting
bsoncxx::v1::stdx::optional< bool > enable_overload_retargeting() const
Return the "enableOverloadRetargeting" option.
mongocxx::v1::uri::replica_set
bsoncxx::v1::stdx::string_view replica_set() const
Return the "replicaSet" option.
mongocxx::v1::uri::tls_insecure
bsoncxx::v1::stdx::optional< bool > tls_insecure() const
Return the "tlsInsecure" option.
mongocxx::v1::uri::password
bsoncxx::v1::stdx::string_view password() const
Return the password specified by the connection string.
mongocxx::v1::uri::max_adaptive_retries
bsoncxx::v1::stdx::optional< std::int32_t > max_adaptive_retries() const
Return the "maxAdaptiveRetries" option.
mongocxx::v1::uri::read_preference
v1::read_preference read_preference() const
Return the "readPreference" option.
mongocxx::v1::uri::socket_timeout_ms
bsoncxx::v1::stdx::optional< std::int32_t > socket_timeout_ms() const
Return the "socketTimeoutMS" option.
mongocxx::v1::uri::credentials
bsoncxx::v1::stdx::optional< bsoncxx::v1::document::view > credentials() const
Return the mongoc "credentials" field containing "authMechanism" and related options.
mongocxx::v1::uri::write_concern
v1::write_concern write_concern() const
Return the "writeConcern" option.
mongocxx::v1::uri::database
bsoncxx::v1::stdx::string_view database() const
Return the database name specified by the connection string.
mongocxx::v1::uri::make_error_code
friend std::error_code make_error_code(errc v)
Support implicit conversion to std::error_code.
Definition uri.hpp:387
mongocxx::v1::uri::auth_source
bsoncxx::v1::stdx::string_view auth_source() const
Return the "authSource" option.
mongocxx::v1::uri::auth_mechanism
bsoncxx::v1::stdx::string_view auth_mechanism() const
Return the "authMechanism" option.
mongocxx::v1::uri::appname
bsoncxx::v1::stdx::optional< bsoncxx::v1::stdx::string_view > appname() const
Return the "appName" option.
mongocxx::v1::uri::compressors
std::vector< bsoncxx::v1::stdx::string_view > compressors() const
Return the "compressors" option.
mongocxx::v1::uri::tls_allow_invalid_hostnames
bsoncxx::v1::stdx::optional< bool > tls_allow_invalid_hostnames() const
Return the "tlsAllowInvalidHostnames" option.
mongocxx::v1::uri::username
bsoncxx::v1::stdx::string_view username() const
Return the username specified by the connection string.
mongocxx::v1::uri::tls_disable_ocsp_endpoint_check
bsoncxx::v1::stdx::optional< bool > tls_disable_ocsp_endpoint_check() const
Return the (mongoc-specific) "tlsDisableOCSPEndpointCheck" option.
mongocxx::v1::uri::retry_writes
bsoncxx::v1::stdx::optional< bool > retry_writes() const
Return the "retryWrites" option.
mongocxx::v1::uri::error_category
static std::error_category const & error_category()
The error category for mongocxx::v1::uri::errc.
mongocxx::v1::uri::tls
bool tls() const
Return the "tls" option.
mongocxx::v1::uri::srv_max_hosts
bsoncxx::v1::stdx::optional< std::int32_t > srv_max_hosts() const
Return the "srvMaxHosts" option.
mongocxx::v1::uri::to_string
bsoncxx::v1::stdx::string_view to_string() const
Return this URI as a connection string.
mongocxx::v1::uri::heartbeat_frequency_ms
bsoncxx::v1::stdx::optional< std::int32_t > heartbeat_frequency_ms() const
Return the "heartbeatFrequencyMS" option.
mongocxx::v1::uri::~uri
~uri()
Destroy this object.
mongocxx::v1::uri::tls_certificate_key_file
bsoncxx::v1::stdx::optional< bsoncxx::v1::stdx::string_view > tls_certificate_key_file() const
Return the "tlsCertificateKeyFile" option.
mongocxx::v1::uri::wait_queue_timeout_ms
bsoncxx::v1::stdx::optional< std::int32_t > wait_queue_timeout_ms() const
Return the "waitQueueTimeoutMS" option.
mongocxx::v1::uri::connect_timeout_ms
bsoncxx::v1::stdx::optional< std::int32_t > connect_timeout_ms() const
Return the "connectTimeoutMS" option.
mongocxx::v1::uri::hosts
std::vector< host > hosts() const
Return the host(s) identifiers specified by the connection string.
mongocxx::v1::uri::uri
uri()
Equivalent to uri(bsoncxx::v1::stdx::string_view v) with k_default_uri.
mongocxx::v1::uri::options
bsoncxx::v1::document::view options() const
Return all URI options that were specified by the connection string.
mongocxx::v1::uri::auth_mechanism_properties
bsoncxx::v1::stdx::optional< bsoncxx::v1::document::view > auth_mechanism_properties() const
Return the "authMechanismProperties" option.
mongocxx::v1::uri::local_threshold_ms
bsoncxx::v1::stdx::optional< std::int32_t > local_threshold_ms() const
Return the "localThresholdMS" option.
mongocxx::v1::uri::tls_ca_file
bsoncxx::v1::stdx::optional< bsoncxx::v1::stdx::string_view > tls_ca_file() const
Return the "tlsCAFile" option.
export.hpp
Provides macros to control the set of symbols exported in the ABI.
MONGOCXX_ABI_EXPORT_CDECL
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition export.hpp:52
postlude.hpp
The mongocxx v1 macro guard postlude header.
prelude.hpp
The mongocxx v1 macro guard prelude header.
bsoncxx
The top-level namespace within which all bsoncxx library entities are declared.
mongocxx::v1
Declares entities whose ABI stability is guaranteed for documented symbols.
mongocxx::v1::source_errc::mongocxx
@ mongocxx
From the mongocxx library.
Definition exception.hpp:40
mongocxx
The top-level namespace within which all mongocxx library entities are declared.
mongocxx::v1::uri::host
A host identifier.
Definition uri.hpp:97
mongocxx::v1::uri::host::family
std::int32_t family
The address family.
Definition uri.hpp:100
mongocxx::v1::uri::host::port
std::uint16_t port
The port number.
Definition uri.hpp:99
mongocxx::v1::uri::host::name
std::string name
The host name.
Definition uri.hpp:98
view-fwd.hpp
Declares bsoncxx::v1::document::view.
read_concern-fwd.hpp
Declares mongocxx::v1::read_concern.
read_preference-fwd.hpp
Declares mongocxx::v1::read_preference.
optional.hpp
Provides std::optional-related polyfills for library API usage.
string_view.hpp
Provides std::string_view-related polyfills for library API usage.
uri-fwd.hpp
Declares mongocxx::v1::uri.
write_concern-fwd.hpp
Declares mongocxx::v1::write_concern.