MongoDB C++ Driver mongocxx-3.6.7
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/document/view_or_value.hpp>
23#include <bsoncxx/stdx/optional.hpp>
24#include <mongocxx/options/transaction.hpp>
25#include <mongocxx/stdx.hpp>
26
27#include <mongocxx/config/prelude.hpp>
28
29namespace mongocxx {
30MONGOCXX_INLINE_NAMESPACE_BEGIN
31
32class client;
33class collection;
34class database;
35class uri;
36
37namespace events {
38class topology_description;
39}
40
62class MONGOCXX_API read_preference {
63 public:
75 enum class read_mode : std::uint8_t {
79 k_primary,
80
84 k_primary_preferred,
85
89 k_secondary,
90
94 k_secondary_preferred,
95
99 k_nearest
100 };
101
106
107 struct deprecated_tag {};
108
117 MONGOCXX_DEPRECATED read_preference(read_mode mode);
119
134
139
144
149
153 read_preference& operator=(read_preference&&) noexcept;
154
159
171
177 read_mode mode() const;
178
191 read_preference& tags(bsoncxx::document::view_or_value tags);
192
200 stdx::optional<bsoncxx::document::view> tags() const;
201
232 read_preference& max_staleness(std::chrono::seconds max_staleness);
233
239 stdx::optional<std::chrono::seconds> max_staleness() const;
240
259 read_preference& hedge(bsoncxx::document::view_or_value hedge);
260
266 const stdx::optional<bsoncxx::document::view> hedge() const;
267
268 private:
269 friend client;
270 friend collection;
271 friend database;
272 friend options::transaction;
273 friend events::topology_description;
274 friend uri;
275
283 friend MONGOCXX_API bool MONGOCXX_CALL operator==(const read_preference&,
284 const read_preference&);
285 friend MONGOCXX_API bool MONGOCXX_CALL operator!=(const read_preference&,
286 const read_preference&);
290
291 class MONGOCXX_PRIVATE impl;
292
293 MONGOCXX_PRIVATE read_preference(std::unique_ptr<impl>&& implementation);
294
295 std::unique_ptr<impl> _impl;
296};
297
298MONGOCXX_INLINE_NAMESPACE_END
299} // namespace mongocxx
300
301#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:81
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:62
read_mode
Determines which members in a replica set are acceptable to read from.
Definition: read_preference.hpp:75
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.
MONGOCXX_DEPRECATED read_preference(read_mode mode, bsoncxx::document::view_or_value tags)
Constructs a new read_preference with tags.
MONGOCXX_DEPRECATED read_preference(read_mode mode)
Constructs a new 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:107