MongoDB C++ Driver 4.4.0
Loading...
Searching...
No Matches
uri.hpp
Go to the documentation of this file.
1// Copyright 2009-present MongoDB, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <mongocxx/uri-fwd.hpp> // IWYU pragma: export
18
19//
20
22
23#include <mongocxx/v1/uri.hpp> // IWYU pragma: export
24
25#include <cstdint>
26#include <memory> // IWYU pragma: keep: backward compatibility, to be removed.
27#include <string>
28#include <type_traits>
29#include <utility>
30#include <vector>
31
32#include <mongocxx/client-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
33#include <mongocxx/pool-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
34
39
43
45
46namespace mongocxx {
47namespace v_noabi {
48
55class uri {
56 private:
57 v1::uri _uri;
58
59 public:
60 using host = v1::uri::host;
61
66
74 /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE() uri(bsoncxx::v_noabi::string::view_or_value uri_string);
75
76 template <
77 typename T,
78 bsoncxx::detail::enable_if_t<std::is_convertible<T, bsoncxx::v_noabi::string::view_or_value>::value>* = nullptr>
79 /* explicit(false) */ uri(T t) : uri{bsoncxx::v_noabi::string::view_or_value{t}} {
80 // For backward compatibility: avoid ambiguity with the new v1::uri ctor.
81 }
82
83
90 uri() : uri{bsoncxx::v_noabi::string::view_or_value{k_default_uri}} {}
91
95 uri(uri&& other) noexcept = default;
96
100 uri& operator=(uri&& other) noexcept = default;
101
105 ~uri() = default;
106
107 uri(uri const& other) = delete;
108 uri& operator=(uri const& other) = delete;
109
113 /* explicit(false) */ uri(v1::uri uri) : _uri{std::move(uri)} {}
114
123 explicit operator v1::uri() && {
124 return std::move(_uri);
125 }
126
130 explicit operator v1::uri() const& {
131 return _uri;
132 }
133
139 std::string auth_mechanism() const {
140 return std::string{_uri.auth_mechanism()};
141 }
142
148 std::string auth_source() const {
149 return std::string{_uri.auth_source()};
150 }
151
157 std::vector<host> hosts() const {
158 return _uri.hosts();
159 }
160
166 std::string database() const {
167 return std::string{_uri.database()};
168 }
169
180 return _uri.options();
181 }
182
188 std::string password() const {
189 return std::string{_uri.password()};
190 }
191
198 return _uri.read_concern();
199 }
200
207 return _uri.read_preference();
208 }
209
215 std::string replica_set() const {
216 return std::string{_uri.replica_set()};
217 }
218
226 bool ssl() const {
227 return _uri.tls();
228 }
229
235 bool tls() const {
236 return _uri.tls();
237 }
238
244 std::string to_string() const {
245 return std::string{_uri.to_string()};
246 }
247
253 std::string username() const {
254 return std::string{_uri.username()};
255 }
256
263 return _uri.write_concern();
264 }
265
274
281 return _uri.auth_mechanism_properties();
282 }
283
291
297 bsoncxx::v_noabi::stdx::optional<std::int32_t> srv_max_hosts() const {
298 return _uri.srv_max_hosts();
299 }
300
307 std::vector<bsoncxx::v_noabi::stdx::string_view> compressors() const {
308 return _uri.compressors();
309 }
310
317 return _uri.connect_timeout_ms();
318 }
319
326 return _uri.direct_connection();
327 }
328
335 return _uri.heartbeat_frequency_ms();
336 }
337
344 return _uri.local_threshold_ms();
345 }
346
353 return _uri.max_adaptive_retries();
354 }
355
362 return _uri.enable_overload_retargeting();
363 }
364
371 return _uri.max_pool_size();
372 }
373
380 return _uri.retry_reads();
381 }
382
389 return _uri.retry_writes();
390 }
391
398 return _uri.server_selection_timeout_ms();
399 }
400
407 return _uri.server_selection_try_once();
408 }
409
418
425 return _uri.socket_timeout_ms();
426 }
427
434 return _uri.tls_allow_invalid_certificates();
435 }
436
443 return _uri.tls_allow_invalid_hostnames();
444 }
445
454
463
470 return _uri.tls_certificate_key_file_password();
471 }
472
480 return _uri.tls_disable_certificate_revocation_check();
481 }
482
489 return _uri.tls_disable_ocsp_endpoint_check();
490 }
491
498 return _uri.tls_insecure();
499 }
500
507 return _uri.wait_queue_timeout_ms();
508 }
509
516 return _uri.zlib_compression_level();
517 }
518
519 class internal;
520};
521
526 return {std::move(v)};
527}
528
533 return v1::uri{std::move(v)};
534}
535
536} // namespace v_noabi
537} // namespace mongocxx
538
540
A polyfill for std::optional<T>.
Definition optional.hpp:799
A read-only, non-owning view of a BSON document.
Definition view.hpp:40
A view-or-value variant type for strings.
Definition view_or_value.hpp:41
uri(bsoncxx::v_noabi::string::view_or_value uri_string)
Constructs a uri from the provided MongoDB URI string.
A MongoDB connection string.
Definition uri.hpp:89
Controls the consistency and isolation properties of data read from replica sets and sharded clusters...
Definition read_concern.hpp:54
read_concern()=default
Constructs a new read_concern with default acknowledge_level of k_server_default.
Describes how MongoDB clients route read operations to the members of a replica set or sharded cluste...
Definition read_preference.hpp:59
read_preference()=default
Constructs a new read_preference with read_mode set to k_primary.
A MongoDB connection string URI.
Definition uri.hpp:55
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
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
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
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
bool ssl() const
Returns the ssl parameter from the uri.
Definition uri.hpp:226
std::vector< host > hosts() const
Returns the hosts from the uri.
Definition uri.hpp:157
std::string auth_mechanism() const
Returns the authentication mechanism from the uri.
Definition uri.hpp:139
uri(v1::uri uri)
Construct with the mongocxx::v1 equivalent.
Definition uri.hpp:113
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
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
v_noabi::read_concern read_concern() const
Returns the read concern from the uri.
Definition uri.hpp:197
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
void server_selection_try_once(bool val)
Sets the value of the option "serverSelectionTryOnce" in the uri.
uri(bsoncxx::v_noabi::string::view_or_value uri_string)
Constructs a uri from the provided MongoDB URI string.
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
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
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
std::string database() const
Returns the database from the uri.
Definition uri.hpp:166
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
bool tls() const
Returns the tls parameter from the uri.
Definition uri.hpp:235
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
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view > credentials()
Returns the value of the option credentials if present in the uri.
std::string auth_source() const
Returns the authentication source from the uri.
Definition uri.hpp:148
std::string to_string() const
Returns the uri in a string format.
Definition uri.hpp:244
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
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
v_noabi::write_concern write_concern() const
Returns the write concern specified in the uri.
Definition uri.hpp:262
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
bsoncxx::v_noabi::document::view options() const
Returns other uri options.
Definition uri.hpp:179
static const std::string k_default_uri
The default URI string: "mongodb://localhost:27017".
Definition uri.hpp:65
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
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
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
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
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
std::string username() const
Returns the supplied username from the uri.
Definition uri.hpp:253
uri()
Constructs a uri from the default MongoDB URI string: "mongodb://localhost:27017".
Definition uri.hpp:90
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
uri(uri &&other) noexcept=default
Move constructs a uri.
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
~uri()=default
Destroys a uri.
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
uri & operator=(uri &&other) noexcept=default
Move assigns a uri.
std::string password() const
Returns the password from the uri.
Definition uri.hpp:188
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
std::string replica_set() const
Returns the replica set specified in the uri.
Definition uri.hpp:215
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
v_noabi::read_preference read_preference() const
Returns the read preference from the uri.
Definition uri.hpp:206
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
The level of acknowledgment requested for write operations to a MongoDB server.
Definition write_concern.hpp:54
write_concern()=default
Constructs a new write_concern.
#define MONGOCXX_ABI_EXPORT_UNSTABLE
Exports the associated entity as part of the unstable ABI.
Definition config.hpp:23
#define MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(...)
Equivalent to MONGOCXX_ABI_EXPORT_UNSTABLE with MONGOCXX_ABI_CDECL.
Definition config.hpp:28
The mongocxx v_noabi macro guard postlude header.
The mongocxx v_noabi macro guard prelude header.
The top-level namespace within which all bsoncxx library entities are declared.
Declares entities whose ABI stability is NOT guaranteed.
v1::bulk_write to_v1(v_noabi::bulk_write v)
Convert to the mongocxx::v1 equivalent of v.
Definition bulk_write.hpp:162
v_noabi::bulk_write from_v1(v1::bulk_write v)
Convert to the mongocxx::v_noabi equivalent of v.
Definition bulk_write.hpp:155
The top-level namespace within which all mongocxx library entities are declared.
Provides bsoncxx::v_noabi::string::view_or_value.
A host identifier.
Definition uri.hpp:97
For internal use only!
Provides mongocxx::v1::uri.
Provides bsoncxx::v_noabi::document::view.
Provides std::optional-related polyfills for library API usage.
Provides std::string_view-related polyfills for library API usage.
Declares mongocxx::v_noabi::client.
Declares mongocxx::v_noabi::pool.
Provides mongocxx::v_noabi::read_concern.
Provides mongocxx::v_noabi::read_preference.
Declares mongocxx::v_noabi::uri.
Provides mongocxx::v_noabi::write_concern.