MongoDB C++ Driver mongocxx-3.4.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/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
241 private:
242 friend client;
243 friend collection;
244 friend database;
245 friend options::transaction;
246 friend events::topology_description;
247 friend uri;
248
256 friend MONGOCXX_API bool MONGOCXX_CALL operator==(const read_preference&,
257 const read_preference&);
258 friend MONGOCXX_API bool MONGOCXX_CALL operator!=(const read_preference&,
259 const read_preference&);
263
264 class MONGOCXX_PRIVATE impl;
265
266 MONGOCXX_PRIVATE read_preference(std::unique_ptr<impl>&& implementation);
267
268 std::unique_ptr<impl> _impl;
269};
270
271MONGOCXX_INLINE_NAMESPACE_END
272} // namespace mongocxx
273
274#include <mongocxx/config/postlude.hpp>
Class representing a client connection to MongoDB.
Definition client.hpp:57
Class representing server side document groupings within a MongoDB database.
Definition collection.hpp:85
Class representing a MongoDB database.
Definition database.hpp:44
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(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:40
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