MongoDB C++ Driver mongocxx-3.11.0
Loading...
Searching...
No Matches
read_preference.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 <chrono>
18#include <cstdint>
19#include <memory>
20#include <string>
21
29#include <mongocxx/uri-fwd.hpp>
30
34
36#include <mongocxx/stdx.hpp>
37
39
40namespace mongocxx {
41namespace v_noabi {
42
66 public:
79 enum class read_mode : std::uint8_t {
84
89
94
99
104 };
105
110
111 struct deprecated_tag {};
112
122
124
139 read_preference(read_mode mode, bsoncxx::v_noabi::document::view_or_value tags);
140
142 read_preference(read_mode mode, bsoncxx::v_noabi::document::view_or_value tags, deprecated_tag);
143
148
153
158
163
168
180
187
202 tags(bsoncxx::v_noabi::document::view_or_value tag_set_list);
203
218 tags(bsoncxx::v_noabi::array::view_or_value tag_set_list);
219
228 MONGOCXX_ABI_EXPORT_CDECL(stdx::optional<bsoncxx::v_noabi::document::view>) tags() const;
229
261
267 MONGOCXX_ABI_EXPORT_CDECL(stdx::optional<std::chrono::seconds>) max_staleness() const;
268
288 hedge(bsoncxx::v_noabi::document::view_or_value hedge);
289
295 MONGOCXX_ABI_EXPORT_CDECL(const stdx::optional<bsoncxx::v_noabi::document::view>) hedge() const;
296
303 friend MONGOCXX_ABI_EXPORT_CDECL(bool) operator==(const read_preference&,
304 const read_preference&);
305 friend MONGOCXX_ABI_EXPORT_CDECL(bool) operator!=(const read_preference&,
306 const read_preference&);
309
310 private:
311 friend ::mongocxx::v_noabi::client;
312 friend ::mongocxx::v_noabi::collection;
313 friend ::mongocxx::v_noabi::database;
314 friend ::mongocxx::v_noabi::events::topology_description;
315 friend ::mongocxx::v_noabi::options::transaction;
316 friend ::mongocxx::v_noabi::search_index_view;
317 friend ::mongocxx::v_noabi::uri;
318
319 class impl;
320
321 read_preference(std::unique_ptr<impl>&& implementation);
322
323 std::unique_ptr<impl> _impl;
324};
325
326} // namespace v_noabi
327} // namespace mongocxx
328
329#include <mongocxx/config/postlude.hpp>
330
Provides bsoncxx::v_noabi::array::view_or_value.
Class representing a client connection to MongoDB.
Definition client.hpp:62
Class representing server side document groupings within a MongoDB database.
Definition collection.hpp:87
Class representing a MongoDB database.
Definition database.hpp:47
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition read_preference.hpp:65
stdx::optional< std::chrono::seconds > max_staleness() const
Returns the current max staleness setting for this read_preference.
const stdx::optional< bsoncxx::v_noabi::document::view > hedge() const
Gets the current hedge document to be used for the read preference.
stdx::optional< bsoncxx::v_noabi::document::view > tags() const
Sets or updates the tag set list for this read_preference.
read_mode
Determines which members in a replica set are acceptable to read from.
Definition read_preference.hpp:79
@ k_nearest
Read from the node with the lowest latency irrespective of state.
@ k_primary
Only read from a primary node.
@ k_secondary_preferred
Prefer to read from secondary nodes.
@ k_secondary
Only read from secondary nodes.
@ k_primary_preferred
Prefer to read from a primary node.
read_mode mode() const
Returns the current read_mode for this read_preference.
Class representing a MongoDB search index view.
Definition search_index_view.hpp:24
Class representing a MongoDB connection string URI.
Definition uri.hpp:43
Declares mongocxx::v_noabi::client.
Declares mongocxx::v_noabi::collection.
Declares mongocxx::v_noabi::database.
Provides bsoncxx::v_noabi::document::view_or_value.
#define MONGOCXX_DEPRECATED
Declares the associated entity as deprecated.
Definition fwd.hpp:258
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition fwd.hpp:222
The mongocxx macro guard prelude header.
The top-level namespace within which all bsoncxx library entities are declared.
The top-level namespace within which all mongocxx library entities are declared.
The top-level namespace reserved for the C++ standard library.
Provides std::optional-related polyfills for library API usage.
Declares mongocxx::v_noabi::read_preference.
Declares mongocxx::v_noabi::search_index_view.
Redeclares bsoncxx::v_noabi::stdx in mongocxx::v_noabi::stdx for internal use.
Definition read_preference.hpp:111
Declares mongocxx::v_noabi::events::topology_description.
Declares mongocxx::v_noabi::options::transaction.
Provides mongocxx::v_noabi::options::transaction.
Declares mongocxx::v_noabi::uri.