MongoDB C++ Driver  mongocxx-3.4.2
All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
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 
29 namespace mongocxx {
30 MONGOCXX_INLINE_NAMESPACE_BEGIN
31 
32 class client;
33 class collection;
34 class database;
35 class uri;
36 
37 namespace events {
38 class topology_description;
39 }
40 
62 class 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 
105  read_preference();
106 
107  struct deprecated_tag {};
108 
117  MONGOCXX_DEPRECATED read_preference(read_mode mode);
118  read_preference(read_mode mode, deprecated_tag);
119 
132  MONGOCXX_DEPRECATED read_preference(read_mode mode, bsoncxx::document::view_or_value tags);
133  read_preference(read_mode mode, bsoncxx::document::view_or_value tags, deprecated_tag);
134 
138  read_preference(const read_preference&);
139 
143  read_preference& operator=(const read_preference&);
144 
148  read_preference(read_preference&&) noexcept;
149 
153  read_preference& operator=(read_preference&&) noexcept;
154 
158  ~read_preference();
159 
170  read_preference& mode(read_mode mode);
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;
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 
271 MONGOCXX_INLINE_NAMESPACE_END
272 } // namespace mongocxx
273 
274 #include <mongocxx/config/postlude.hpp>
Class representing a MongoDB connection string URI.
Definition: uri.hpp:40
Class representing the optional arguments for a transaction.
Definition: transaction.hpp:37
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:24
Class representing a client connection to MongoDB.
Definition: client.hpp:57
Definition: read_preference.hpp:107
Class representing a MongoDB database.
Definition: database.hpp:44
Class representing what the driver knows about a topology of MongoDB servers: either a standalone...
Definition: topology_description.hpp:37
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
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:85