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/uri-fwd.hpp> // IWYU pragma: export
//
#include <bsoncxx/v1/detail/type_traits.hpp>
#include <mongocxx/v1/uri.hpp> // IWYU pragma: export
#include <cstdint>
#include <memory> // IWYU pragma: keep: backward compatibility, to be removed.
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
#include <mongocxx/client-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/pool-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <bsoncxx/document/view.hpp>
#include <bsoncxx/stdx/optional.hpp>
#include <bsoncxx/stdx/string_view.hpp>
#include <bsoncxx/string/view_or_value.hpp>
#include <mongocxx/read_concern.hpp>
#include <mongocxx/read_preference.hpp>
#include <mongocxx/write_concern.hpp>
#include <mongocxx/config/prelude.hpp>
namespace mongocxx {
namespace v_noabi {
class uri {
private:
v1::uri _uri;
public:
using host = v1::uri::host;
static MONGOCXX_ABI_EXPORT_UNSTABLE const std::string k_default_uri;
/* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE() uri(bsoncxx::v_noabi::string::view_or_value uri_string);
template <
typename T,
bsoncxx::detail::enable_if_t<std::is_convertible<T, bsoncxx::v_noabi::string::view_or_value>::value>* = nullptr>
/* explicit(false) */ uri(T t) : uri{bsoncxx::v_noabi::string::view_or_value{t}} {
// For backward compatibility: avoid ambiguity with the new v1::uri ctor.
}
uri() : uri{bsoncxx::v_noabi::string::view_or_value{k_default_uri}} {}
uri(uri&& other) noexcept = default;
uri& operator=(uri&& other) noexcept = default;
~uri() = default;
uri(uri const& other) = delete;
uri& operator=(uri const& other) = delete;
/* explicit(false) */ uri(v1::uri uri) : _uri{std::move(uri)} {}
explicit operator v1::uri() && {
return std::move(_uri);
}
explicit operator v1::uri() const& {
return _uri;
}
std::string auth_mechanism() const {
return std::string{_uri.auth_mechanism()};
}
std::string auth_source() const {
return std::string{_uri.auth_source()};
}
std::vector<host> hosts() const {
return _uri.hosts();
}
std::string database() const {
return std::string{_uri.database()};
}
bsoncxx::v_noabi::document::view options() const {
return _uri.options();
}
std::string password() const {
return std::string{_uri.password()};
}
v_noabi::read_concern read_concern() const {
return _uri.read_concern();
}
v_noabi::read_preference read_preference() const {
return _uri.read_preference();
}
std::string replica_set() const {
return std::string{_uri.replica_set()};
}
bool ssl() const {
return _uri.tls();
}
bool tls() const {
return _uri.tls();
}
std::string to_string() const {
return std::string{_uri.to_string()};
}
std::string username() const {
return std::string{_uri.username()};
}
v_noabi::write_concern write_concern() const {
return _uri.write_concern();
}
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::stdx::string_view> appname() const {
return _uri.appname();
}
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view> auth_mechanism_properties() const {
return _uri.auth_mechanism_properties();
}
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view>)
credentials();
bsoncxx::v_noabi::stdx::optional<std::int32_t> srv_max_hosts() const {
return _uri.srv_max_hosts();
}
std::vector<bsoncxx::v_noabi::stdx::string_view> compressors() const {
return _uri.compressors();
}
bsoncxx::v_noabi::stdx::optional<std::int32_t> connect_timeout_ms() const {
return _uri.connect_timeout_ms();
}
bsoncxx::v_noabi::stdx::optional<bool> direct_connection() const {
return _uri.direct_connection();
}
bsoncxx::v_noabi::stdx::optional<std::int32_t> heartbeat_frequency_ms() const {
return _uri.heartbeat_frequency_ms();
}
bsoncxx::v_noabi::stdx::optional<std::int32_t> local_threshold_ms() const {
return _uri.local_threshold_ms();
}
bsoncxx::v_noabi::stdx::optional<std::int32_t> max_adaptive_retries() const {
return _uri.max_adaptive_retries();
}
bsoncxx::v_noabi::stdx::optional<bool> enable_overload_retargeting() const {
return _uri.enable_overload_retargeting();
}
bsoncxx::v_noabi::stdx::optional<std::int32_t> max_pool_size() const {
return _uri.max_pool_size();
}
bsoncxx::v_noabi::stdx::optional<bool> retry_reads() const {
return _uri.retry_reads();
}
bsoncxx::v_noabi::stdx::optional<bool> retry_writes() const {
return _uri.retry_writes();
}
bsoncxx::v_noabi::stdx::optional<std::int32_t> server_selection_timeout_ms() const {
return _uri.server_selection_timeout_ms();
}
bsoncxx::v_noabi::stdx::optional<bool> server_selection_try_once() const {
return _uri.server_selection_try_once();
}
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(void) server_selection_try_once(bool val);
bsoncxx::v_noabi::stdx::optional<std::int32_t> socket_timeout_ms() const {
return _uri.socket_timeout_ms();
}
bsoncxx::v_noabi::stdx::optional<bool> tls_allow_invalid_certificates() const {
return _uri.tls_allow_invalid_certificates();
}
bsoncxx::v_noabi::stdx::optional<bool> tls_allow_invalid_hostnames() const {
return _uri.tls_allow_invalid_hostnames();
}
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::stdx::string_view> tls_ca_file() const {
return _uri.tls_ca_file();
}
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::stdx::string_view> tls_certificate_key_file() const {
return _uri.tls_certificate_key_file();
}
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::stdx::string_view> tls_certificate_key_file_password() const {
return _uri.tls_certificate_key_file_password();
}
bsoncxx::v_noabi::stdx::optional<bool> tls_disable_certificate_revocation_check() const {
return _uri.tls_disable_certificate_revocation_check();
}
bsoncxx::v_noabi::stdx::optional<bool> tls_disable_ocsp_endpoint_check() const {
return _uri.tls_disable_ocsp_endpoint_check();
}
bsoncxx::v_noabi::stdx::optional<bool> tls_insecure() const {
return _uri.tls_insecure();
}
bsoncxx::v_noabi::stdx::optional<std::int32_t> wait_queue_timeout_ms() const {
return _uri.wait_queue_timeout_ms();
}
bsoncxx::v_noabi::stdx::optional<std::int32_t> zlib_compression_level() const {
return _uri.zlib_compression_level();
}
class internal;
};
inline v_noabi::uri from_v1(v1::uri v) {
return {std::move(v)};
}
inline v1::uri to_v1(v_noabi::uri v) {
return v1::uri{std::move(v)};
}
} // namespace v_noabi
} // namespace mongocxx
#include <mongocxx/config/postlude.hpp>
bsoncxx::v1::stdx::optional
A polyfill for std::optional<T>.
Definition optional.hpp:799
bsoncxx::v_noabi::document::view
A read-only, non-owning view of a BSON document.
Definition view.hpp:40
bsoncxx::v_noabi::string::view_or_value
A view-or-value variant type for strings.
Definition view_or_value.hpp:41
mongocxx::uri::uri
uri(bsoncxx::v_noabi::string::view_or_value uri_string)
Constructs a uri from the provided MongoDB URI string.
mongocxx::v1::uri
A MongoDB connection string.
Definition uri.hpp:89
mongocxx::v_noabi::read_concern
Controls the consistency and isolation properties of data read from replica sets and sharded clusters...
Definition read_concern.hpp:54
mongocxx::v_noabi::read_concern::read_concern
read_concern()=default
Constructs a new read_concern with default acknowledge_level of k_server_default.
mongocxx::v_noabi::read_preference
Describes how MongoDB clients route read operations to the members of a replica set or sharded cluste...
Definition read_preference.hpp:59
mongocxx::v_noabi::read_preference::read_preference
read_preference()=default
Constructs a new read_preference with read_mode set to k_primary.
mongocxx::v_noabi::uri
A MongoDB connection string URI.
Definition uri.hpp:55
mongocxx::v_noabi::uri::tls_ca_file
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::stdx::string_view > tls_ca_file() const
Returns the value of the option "tlsCAFile" if present in the uri.
Definition uri.hpp:451
mongocxx::v_noabi::uri::server_selection_try_once
bsoncxx::v_noabi::stdx::optional< bool > server_selection_try_once() const
Returns the value of the option "serverSelectionTryOnce" if present in the uri.
Definition uri.hpp:406
mongocxx::v_noabi::uri::tls_insecure
bsoncxx::v_noabi::stdx::optional< bool > tls_insecure() const
Returns the value of the option "tlsInsecure" if present in the uri.
Definition uri.hpp:497
mongocxx::v_noabi::uri::tls_certificate_key_file
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::stdx::string_view > tls_certificate_key_file() const
Returns the value of the option "tlsCertificateKeyFile" if present in the uri.
Definition uri.hpp:460
mongocxx::v_noabi::uri::ssl
bool ssl() const
Returns the ssl parameter from the uri.
Definition uri.hpp:226
mongocxx::v_noabi::uri::hosts
std::vector< host > hosts() const
Returns the hosts from the uri.
Definition uri.hpp:157
mongocxx::v_noabi::uri::auth_mechanism
std::string auth_mechanism() const
Returns the authentication mechanism from the uri.
Definition uri.hpp:139
mongocxx::v_noabi::uri::uri
uri(v1::uri uri)
Construct with the mongocxx::v1 equivalent.
Definition uri.hpp:113
mongocxx::v_noabi::uri::zlib_compression_level
bsoncxx::v_noabi::stdx::optional< std::int32_t > zlib_compression_level() const
Returns the value of the option "zlibCompressionLevel" if present in the uri.
Definition uri.hpp:515
mongocxx::v_noabi::uri::max_pool_size
bsoncxx::v_noabi::stdx::optional< std::int32_t > max_pool_size() const
Returns the value of the option "maxPoolSize" if present in the uri.
Definition uri.hpp:370
mongocxx::v_noabi::uri::read_concern
v_noabi::read_concern read_concern() const
Returns the read concern from the uri.
Definition uri.hpp:197
mongocxx::v_noabi::uri::connect_timeout_ms
bsoncxx::v_noabi::stdx::optional< std::int32_t > connect_timeout_ms() const
Returns the value of the option "connectTimeoutMS" if present in the uri.
Definition uri.hpp:316
mongocxx::v_noabi::uri::server_selection_try_once
void server_selection_try_once(bool val)
Sets the value of the option "serverSelectionTryOnce" in the uri.
mongocxx::v_noabi::uri::uri
uri(bsoncxx::v_noabi::string::view_or_value uri_string)
Constructs a uri from the provided MongoDB URI string.
mongocxx::v_noabi::uri::wait_queue_timeout_ms
bsoncxx::v_noabi::stdx::optional< std::int32_t > wait_queue_timeout_ms() const
Returns the value of the option "waitQueueTimeoutMS" if present in the uri.
Definition uri.hpp:506
mongocxx::v_noabi::uri::auth_mechanism_properties
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view > auth_mechanism_properties() const
Returns the value of the option "authMechanismProperties" if present in the uri.
Definition uri.hpp:280
mongocxx::v_noabi::uri::tls_allow_invalid_certificates
bsoncxx::v_noabi::stdx::optional< bool > tls_allow_invalid_certificates() const
Returns the value of the option "tlsAllowInvalidCertificates" if present in the uri.
Definition uri.hpp:433
mongocxx::v_noabi::uri::database
std::string database() const
Returns the database from the uri.
Definition uri.hpp:166
mongocxx::v_noabi::uri::appname
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::stdx::string_view > appname() const
Returns the value of the option "appname" if present in the uri.
Definition uri.hpp:271
mongocxx::v_noabi::uri::tls
bool tls() const
Returns the tls parameter from the uri.
Definition uri.hpp:235
mongocxx::v_noabi::uri::local_threshold_ms
bsoncxx::v_noabi::stdx::optional< std::int32_t > local_threshold_ms() const
Returns the value of the option "localThresholdMS" if present in the uri.
Definition uri.hpp:343
mongocxx::v_noabi::uri::credentials
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view > credentials()
Returns the value of the option credentials if present in the uri.
mongocxx::v_noabi::uri::auth_source
std::string auth_source() const
Returns the authentication source from the uri.
Definition uri.hpp:148
mongocxx::v_noabi::uri::to_string
std::string to_string() const
Returns the uri in a string format.
Definition uri.hpp:244
mongocxx::v_noabi::uri::server_selection_timeout_ms
bsoncxx::v_noabi::stdx::optional< std::int32_t > server_selection_timeout_ms() const
Returns the value of the option "serverSelectionTimeoutMS" if present in the uri.
Definition uri.hpp:397
mongocxx::v_noabi::uri::heartbeat_frequency_ms
bsoncxx::v_noabi::stdx::optional< std::int32_t > heartbeat_frequency_ms() const
Returns the value of the option "heartbeatFrequencyMS" if present in the uri.
Definition uri.hpp:334
mongocxx::v_noabi::uri::write_concern
v_noabi::write_concern write_concern() const
Returns the write concern specified in the uri.
Definition uri.hpp:262
mongocxx::v_noabi::uri::enable_overload_retargeting
bsoncxx::v_noabi::stdx::optional< bool > enable_overload_retargeting() const
Returns the value of the option "enableOverloadRetargeting" if present in the uri.
Definition uri.hpp:361
mongocxx::v_noabi::uri::options
bsoncxx::v_noabi::document::view options() const
Returns other uri options.
Definition uri.hpp:179
mongocxx::v_noabi::uri::k_default_uri
static const std::string k_default_uri
The default URI string: "mongodb://localhost:27017".
Definition uri.hpp:65
mongocxx::v_noabi::uri::retry_writes
bsoncxx::v_noabi::stdx::optional< bool > retry_writes() const
Returns the value of the option "retryWrites" if present in the uri.
Definition uri.hpp:388
mongocxx::v_noabi::uri::max_adaptive_retries
bsoncxx::v_noabi::stdx::optional< std::int32_t > max_adaptive_retries() const
Returns the value of the option "maxAdaptiveRetries" if present in the uri.
Definition uri.hpp:352
mongocxx::v_noabi::uri::tls_allow_invalid_hostnames
bsoncxx::v_noabi::stdx::optional< bool > tls_allow_invalid_hostnames() const
Returns the value of the option "tlsAllowInvalidHostnames" if present in the uri.
Definition uri.hpp:442
mongocxx::v_noabi::uri::tls_certificate_key_file_password
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::stdx::string_view > tls_certificate_key_file_password() const
Returns the value of the option "tlsCertificateKeyFilePassword" if present in the uri.
Definition uri.hpp:469
mongocxx::v_noabi::uri::compressors
std::vector< bsoncxx::v_noabi::stdx::string_view > compressors() const
Returns the list of compressors present in the uri or an empty list if "compressors" was not present ...
Definition uri.hpp:307
mongocxx::v_noabi::uri::username
std::string username() const
Returns the supplied username from the uri.
Definition uri.hpp:253
mongocxx::v_noabi::uri::uri
uri()
Constructs a uri from the default MongoDB URI string: "mongodb://localhost:27017".
Definition uri.hpp:90
mongocxx::v_noabi::uri::tls_disable_certificate_revocation_check
bsoncxx::v_noabi::stdx::optional< bool > tls_disable_certificate_revocation_check() const
Returns the value of the option "tlsDisableCertificateRevocationCheck" if present in the uri.
Definition uri.hpp:479
mongocxx::v_noabi::uri::uri
uri(uri &&other) noexcept=default
Move constructs a uri.
mongocxx::v_noabi::uri::srv_max_hosts
bsoncxx::v_noabi::stdx::optional< std::int32_t > srv_max_hosts() const
Returns the value of the option "srvMaxHosts" if present in the uri.
Definition uri.hpp:297
mongocxx::v_noabi::uri::~uri
~uri()=default
Destroys a uri.
mongocxx::v_noabi::uri::socket_timeout_ms
bsoncxx::v_noabi::stdx::optional< std::int32_t > socket_timeout_ms() const
Returns the value of the option "socketTimeoutMS" if present in the uri.
Definition uri.hpp:424
mongocxx::v_noabi::uri::operator=
uri & operator=(uri &&other) noexcept=default
Move assigns a uri.
mongocxx::v_noabi::uri::password
std::string password() const
Returns the password from the uri.
Definition uri.hpp:188
mongocxx::v_noabi::uri::direct_connection
bsoncxx::v_noabi::stdx::optional< bool > direct_connection() const
Returns the value of the option "directConnection" if present in the uri.
Definition uri.hpp:325
mongocxx::v_noabi::uri::replica_set
std::string replica_set() const
Returns the replica set specified in the uri.
Definition uri.hpp:215
mongocxx::v_noabi::uri::retry_reads
bsoncxx::v_noabi::stdx::optional< bool > retry_reads() const
Returns the value of the option "retryReads" if present in the uri.
Definition uri.hpp:379
mongocxx::v_noabi::uri::read_preference
v_noabi::read_preference read_preference() const
Returns the read preference from the uri.
Definition uri.hpp:206
mongocxx::v_noabi::uri::tls_disable_ocsp_endpoint_check
bsoncxx::v_noabi::stdx::optional< bool > tls_disable_ocsp_endpoint_check() const
Returns the value of the option "tlsDisableOCSPEndpointCheck" if present in the uri.
Definition uri.hpp:488
mongocxx::v_noabi::write_concern
The level of acknowledgment requested for write operations to a MongoDB server.
Definition write_concern.hpp:54
mongocxx::v_noabi::write_concern::write_concern
write_concern()=default
Constructs a new write_concern.
MONGOCXX_ABI_EXPORT_UNSTABLE
#define MONGOCXX_ABI_EXPORT_UNSTABLE
Exports the associated entity as part of the unstable ABI.
Definition config.hpp:23
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE
#define MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(...)
Equivalent to MONGOCXX_ABI_EXPORT_UNSTABLE with MONGOCXX_ABI_CDECL.
Definition config.hpp:28
postlude.hpp
The mongocxx v_noabi macro guard postlude header.
prelude.hpp
The mongocxx v_noabi macro guard prelude header.
bsoncxx
The top-level namespace within which all bsoncxx library entities are declared.
mongocxx::v_noabi
Declares entities whose ABI stability is NOT guaranteed.
mongocxx::v_noabi::to_v1
v1::bulk_write to_v1(v_noabi::bulk_write v)
Convert to the mongocxx::v1 equivalent of v.
Definition bulk_write.hpp:162
mongocxx::v_noabi::from_v1
v_noabi::bulk_write from_v1(v1::bulk_write v)
Convert to the mongocxx::v_noabi equivalent of v.
Definition bulk_write.hpp:155
mongocxx
The top-level namespace within which all mongocxx library entities are declared.
view_or_value.hpp
Provides bsoncxx::v_noabi::string::view_or_value.
mongocxx::v1::uri::host
A host identifier.
Definition uri.hpp:97
type_traits.hpp
For internal use only!
uri.hpp
Provides mongocxx::v1::uri.
view.hpp
Provides bsoncxx::v_noabi::document::view.
optional.hpp
Provides std::optional-related polyfills for library API usage.
string_view.hpp
Provides std::string_view-related polyfills for library API usage.
client-fwd.hpp
Declares mongocxx::v_noabi::client.
pool-fwd.hpp
Declares mongocxx::v_noabi::pool.
read_concern.hpp
Provides mongocxx::v_noabi::read_concern.
read_preference.hpp
Provides mongocxx::v_noabi::read_preference.
uri-fwd.hpp
Declares mongocxx::v_noabi::uri.
write_concern.hpp
Provides mongocxx::v_noabi::write_concern.