MongoDB C++ Driver mongocxx-3.7.0
Loading...
Searching...
No Matches
read_preference.hpp
1// Copyright 2014 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
22#include <bsoncxx/array/view_or_value.hpp>
23#include <bsoncxx/document/view_or_value.hpp>
24#include <bsoncxx/stdx/optional.hpp>
25#include <mongocxx/options/transaction.hpp>
26#include <mongocxx/stdx.hpp>
27
28#include <mongocxx/config/prelude.hpp>
29
30namespace mongocxx {
31MONGOCXX_INLINE_NAMESPACE_BEGIN
32
33class client;
34class collection;
35class database;
36class uri;
37
38namespace events {
39class topology_description;
40}
41
63class MONGOCXX_API read_preference {
64 public:
76 enum class read_mode : std::uint8_t {
80 k_primary,
81
85 k_primary_preferred,
86
90 k_secondary,
91
95 k_secondary_preferred,
96
100 k_nearest
101 };
102
107
108 struct deprecated_tag {};
109
118 MONGOCXX_DEPRECATED read_preference(read_mode mode);
120
135
140
145
150
154 read_preference& operator=(read_preference&&) noexcept;
155
160
172
178 read_mode mode() const;
179
192 read_preference& tags(bsoncxx::document::view_or_value tag_set_list);
193
206 read_preference& tags(bsoncxx::array::view_or_value tag_set_list);
207
215 stdx::optional<bsoncxx::document::view> tags() const;
216
247 read_preference& max_staleness(std::chrono::seconds max_staleness);
248
254 stdx::optional<std::chrono::seconds> max_staleness() const;
255
274 read_preference& hedge(bsoncxx::document::view_or_value hedge);
275
281 const stdx::optional<bsoncxx::document::view> hedge() const;
282
283 private:
284 friend client;
285 friend collection;
286 friend database;
288 friend mongocxx::options::transaction;
290 friend mongocxx::events::topology_description;
291 friend uri;
292
300 friend MONGOCXX_API bool MONGOCXX_CALL operator==(const read_preference&,
301 const read_preference&);
302 friend MONGOCXX_API bool MONGOCXX_CALL operator!=(const read_preference&,
303 const read_preference&);
307
308 class MONGOCXX_PRIVATE impl;
309
310 MONGOCXX_PRIVATE read_preference(std::unique_ptr<impl>&& implementation);
311
312 std::unique_ptr<impl> _impl;
313};
314
315MONGOCXX_INLINE_NAMESPACE_END
316} // namespace mongocxx
317
318#include <mongocxx/config/postlude.hpp>
Class representing a client connection to MongoDB.
Definition client.hpp:58
Class representing server side document groupings within a MongoDB database.
Definition collection.hpp:83
Class representing a MongoDB database.
Definition database.hpp:43
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition read_preference.hpp:63
read_mode
Determines which members in a replica set are acceptable to read from.
Definition read_preference.hpp:76
read_preference(read_mode mode, bsoncxx::document::view_or_value tags)
Constructs a new read_preference with tags.
read_preference(read_mode mode)
Constructs a new read_preference.
read_preference()
Constructs a new read_preference with read_mode set to k_primary.
read_preference(read_preference &&) noexcept
Move constructs a read_preference.
read_preference(const read_preference &)
Copy constructs a read_preference.
read_preference & operator=(const read_preference &)
Copy assigns a read_preference.
Class representing a MongoDB connection string URI.
Definition uri.hpp:43
Top level namespace for MongoDB C++ BSON functionality.
Definition element.hpp:24
Top level namespace for the MongoDB C++ driver.
Definition bulk_write.hpp:24
Definition read_preference.hpp:108