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/v1/uri-fwd.hpp> // IWYU pragma: export
18
19//
20
22
24
28
32
34
35#include <cstdint>
36#include <string>
37#include <system_error>
38#include <type_traits>
39#include <vector>
40
41namespace mongocxx {
42namespace v1 {
43
89class uri {
90 private:
91 void* _impl; // mongoc_uri_t
92
93 public:
97 struct host {
98 std::string name;
99 std::uint16_t port;
100 std::int32_t family;
101 };
102
106 static constexpr auto k_default_uri = "mongodb://localhost:27017";
107
114
121 MONGOCXX_ABI_EXPORT_CDECL() uri(uri&& other) noexcept;
122
129 MONGOCXX_ABI_EXPORT_CDECL(uri&) operator=(uri&& other) noexcept;
130
135
139 MONGOCXX_ABI_EXPORT_CDECL(uri&) operator=(uri const& other);
140
145
156 /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() uri(bsoncxx::v1::stdx::string_view v);
157
162
166 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) auth_source() const;
167
171 MONGOCXX_ABI_EXPORT_CDECL(std::vector<host>) hosts() const;
172
178 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) database() const;
179
183 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) options() const;
184
188 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) password() const;
189
194
199
203 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) replica_set() const;
204
209
213 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) to_string() const;
214
218 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) username() const;
219
224
228 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::stdx::string_view>) appname() const;
229
234 const;
235
239 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view>) credentials() const;
240
244 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) srv_max_hosts() const;
245
249 MONGOCXX_ABI_EXPORT_CDECL(std::vector<bsoncxx::v1::stdx::string_view>) compressors() const;
250
254 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) connect_timeout_ms() const;
255
259 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) direct_connection() const;
260
264 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) heartbeat_frequency_ms() const;
265
269 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) local_threshold_ms() const;
270
274 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) max_adaptive_retries() const;
275
280
284 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) max_pool_size() const;
285
289 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) retry_reads() const;
290
294 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) retry_writes() const;
295
299 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) server_selection_timeout_ms() const;
300
305
313
317 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) socket_timeout_ms() const;
318
323
328
332 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::stdx::string_view>) tls_ca_file() const;
333
338 const;
339
343 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::stdx::string_view>)
345
350
355
359 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) tls_insecure() const;
360
364 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) wait_queue_timeout_ms() const;
365
369 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) zlib_compression_level() const;
370
374 enum class errc {
377 };
378
382 static MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category();
383
387 friend std::error_code make_error_code(errc v) {
388 return {static_cast<int>(v), error_category()};
389 }
390
391 class internal;
392
393 private:
394 // MSVC may incorrectly select the `void*` ctor given a `char const*` argument without `/Zc:strictStrings`.
395 struct void_ptr {
396 void* impl = nullptr;
397 };
398
399 explicit uri(void_ptr vp);
400};
401
402BSONCXX_PRIVATE_INLINE_CXX17 constexpr char const* uri::k_default_uri;
403
404} // namespace v1
405} // namespace mongocxx
406
407namespace std {
408
409template <>
410struct is_error_code_enum<mongocxx::v1::uri::errc> : true_type {};
411
412} // namespace std
413
415
For internal use only!
bsoncxx::v1::stdx::optional< bool > tls_disable_certificate_revocation_check() const
Return the (mongoc-specific) "tlsDisableCertificateRevocationCheck" option.
bsoncxx::v1::stdx::optional< bool > tls_allow_invalid_certificates() const
Return the "tlsAllowInvalidCertificates" option.
bsoncxx::v1::stdx::optional< bsoncxx::v1::stdx::string_view > tls_certificate_key_file_password() const
Return the "tlsCertificateKeyFilePassword" option.
bsoncxx::v1::stdx::optional< std::int32_t > zlib_compression_level() const
Return the "zlibCompressionLevel" option.
bsoncxx::v1::stdx::optional< bool > server_selection_try_once() const
Return the "serverSelectionTryOnce" option.
static constexpr auto k_default_uri
The default connection string.
Definition uri.hpp:106
bsoncxx::v1::stdx::optional< std::int32_t > server_selection_timeout_ms() const
Return the "serverSelectionTimeoutMS" option.
bsoncxx::v1::stdx::optional< bool > direct_connection() const
Return the "directConnection" option.
v1::read_concern read_concern() const
Return the "readConcern" option.
bsoncxx::v1::stdx::optional< std::int32_t > max_pool_size() const
Return the "maxPoolSize" option.
uri(uri &&other) noexcept
Move constructor.
errc
Errors codes which may be returned by mongocxx::v1::uri.
Definition uri.hpp:374
@ set_failure
Failed to set the requested URI option.
Definition uri.hpp:376
@ zero
Zero.
Definition uri.hpp:375
bsoncxx::v1::stdx::optional< bool > retry_reads() const
Return the "retryReads" option.
bsoncxx::v1::stdx::optional< bool > enable_overload_retargeting() const
Return the "enableOverloadRetargeting" option.
bsoncxx::v1::stdx::string_view replica_set() const
Return the "replicaSet" option.
bsoncxx::v1::stdx::optional< bool > tls_insecure() const
Return the "tlsInsecure" option.
bsoncxx::v1::stdx::string_view password() const
Return the password specified by the connection string.
bsoncxx::v1::stdx::optional< std::int32_t > max_adaptive_retries() const
Return the "maxAdaptiveRetries" option.
v1::read_preference read_preference() const
Return the "readPreference" option.
bsoncxx::v1::stdx::optional< std::int32_t > socket_timeout_ms() const
Return the "socketTimeoutMS" option.
bsoncxx::v1::stdx::optional< bsoncxx::v1::document::view > credentials() const
Return the mongoc "credentials" field containing "authMechanism" and related options.
v1::write_concern write_concern() const
Return the "writeConcern" option.
bsoncxx::v1::stdx::string_view database() const
Return the database name specified by the connection string.
friend std::error_code make_error_code(errc v)
Support implicit conversion to std::error_code.
Definition uri.hpp:387
bsoncxx::v1::stdx::string_view auth_source() const
Return the "authSource" option.
bsoncxx::v1::stdx::string_view auth_mechanism() const
Return the "authMechanism" option.
bsoncxx::v1::stdx::optional< bsoncxx::v1::stdx::string_view > appname() const
Return the "appName" option.
std::vector< bsoncxx::v1::stdx::string_view > compressors() const
Return the "compressors" option.
bsoncxx::v1::stdx::optional< bool > tls_allow_invalid_hostnames() const
Return the "tlsAllowInvalidHostnames" option.
bsoncxx::v1::stdx::string_view username() const
Return the username specified by the connection string.
bsoncxx::v1::stdx::optional< bool > tls_disable_ocsp_endpoint_check() const
Return the (mongoc-specific) "tlsDisableOCSPEndpointCheck" option.
bsoncxx::v1::stdx::optional< bool > retry_writes() const
Return the "retryWrites" option.
static std::error_category const & error_category()
The error category for mongocxx::v1::uri::errc.
bool tls() const
Return the "tls" option.
bsoncxx::v1::stdx::optional< std::int32_t > srv_max_hosts() const
Return the "srvMaxHosts" option.
bsoncxx::v1::stdx::string_view to_string() const
Return this URI as a connection string.
bsoncxx::v1::stdx::optional< std::int32_t > heartbeat_frequency_ms() const
Return the "heartbeatFrequencyMS" option.
~uri()
Destroy this object.
bsoncxx::v1::stdx::optional< bsoncxx::v1::stdx::string_view > tls_certificate_key_file() const
Return the "tlsCertificateKeyFile" option.
bsoncxx::v1::stdx::optional< std::int32_t > wait_queue_timeout_ms() const
Return the "waitQueueTimeoutMS" option.
bsoncxx::v1::stdx::optional< std::int32_t > connect_timeout_ms() const
Return the "connectTimeoutMS" option.
std::vector< host > hosts() const
Return the host(s) identifiers specified by the connection string.
uri()
Equivalent to uri(bsoncxx::v1::stdx::string_view v) with k_default_uri.
bsoncxx::v1::document::view options() const
Return all URI options that were specified by the connection string.
bsoncxx::v1::stdx::optional< bsoncxx::v1::document::view > auth_mechanism_properties() const
Return the "authMechanismProperties" option.
bsoncxx::v1::stdx::optional< std::int32_t > local_threshold_ms() const
Return the "localThresholdMS" option.
bsoncxx::v1::stdx::optional< bsoncxx::v1::stdx::string_view > tls_ca_file() const
Return the "tlsCAFile" option.
Provides macros to control the set of symbols exported in the ABI.
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition export.hpp:52
The mongocxx v1 macro guard postlude header.
The mongocxx v1 macro guard prelude header.
The top-level namespace within which all bsoncxx library entities are declared.
Declares entities whose ABI stability is guaranteed for documented symbols.
@ mongocxx
From the mongocxx library.
Definition exception.hpp:40
The top-level namespace within which all mongocxx library entities are declared.
A host identifier.
Definition uri.hpp:97
std::int32_t family
The address family.
Definition uri.hpp:100
std::uint16_t port
The port number.
Definition uri.hpp:99
std::string name
The host name.
Definition uri.hpp:98
Declares bsoncxx::v1::document::view.
Declares mongocxx::v1::read_concern.
Declares mongocxx::v1::read_preference.
Provides std::optional-related polyfills for library API usage.
Provides std::string_view-related polyfills for library API usage.
Declares mongocxx::v1::uri.
Declares mongocxx::v1::write_concern.