MongoDB C++ Driver  mongocxx-3.10.2
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 <mongocxx/client-fwd.hpp>
23 #include <mongocxx/collection-fwd.hpp>
24 #include <mongocxx/database-fwd.hpp>
25 #include <mongocxx/events/topology_description-fwd.hpp>
26 #include <mongocxx/options/transaction-fwd.hpp>
27 #include <mongocxx/read_preference-fwd.hpp>
28 #include <mongocxx/search_index_view-fwd.hpp>
29 #include <mongocxx/uri-fwd.hpp>
30 
31 #include <bsoncxx/array/view_or_value.hpp>
32 #include <bsoncxx/document/view_or_value.hpp>
33 #include <bsoncxx/stdx/optional.hpp>
34 #include <mongocxx/options/transaction.hpp>
35 #include <mongocxx/stdx.hpp>
36 
37 #include <mongocxx/config/prelude.hpp>
38 
39 namespace mongocxx {
40 namespace v_noabi {
41 
64  public:
76  enum class read_mode : std::uint8_t {
80  k_primary,
81 
86 
91 
96 
100  k_nearest
101  };
102 
107 
108  struct deprecated_tag {};
109 
118  MONGOCXX_DEPRECATED read_preference(read_mode mode);
120 
133  MONGOCXX_DEPRECATED read_preference(read_mode mode,
136 
141 
146 
151 
155  read_preference& operator=(read_preference&&) noexcept;
156 
161 
173 
179  read_mode mode() const;
180 
193  read_preference& tags(bsoncxx::v_noabi::document::view_or_value tag_set_list);
194 
207  read_preference& tags(bsoncxx::v_noabi::array::view_or_value tag_set_list);
208 
216  stdx::optional<bsoncxx::v_noabi::document::view> tags() const;
217 
249 
255  stdx::optional<std::chrono::seconds> max_staleness() const;
256 
275  read_preference& hedge(bsoncxx::v_noabi::document::view_or_value hedge);
276 
282  const stdx::optional<bsoncxx::v_noabi::document::view> hedge() const;
283 
284  private:
285  friend ::mongocxx::v_noabi::client;
286  friend ::mongocxx::v_noabi::collection;
287  friend ::mongocxx::v_noabi::database;
288  friend ::mongocxx::v_noabi::events::topology_description;
289  friend ::mongocxx::v_noabi::options::transaction;
290  friend ::mongocxx::v_noabi::search_index_view;
291  friend ::mongocxx::v_noabi::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 
315 } // namespace v_noabi
316 } // namespace mongocxx
317 
318 #include <mongocxx/config/postlude.hpp>
Class representing a client connection to MongoDB.
Definition: client.hpp:61
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:86
Class representing a MongoDB database.
Definition: database.hpp:46
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition: read_preference.hpp:63
read_preference(read_mode mode)
Constructs a new read_preference.
stdx::optional< std::chrono::seconds > max_staleness() const
Returns the current max staleness setting for this read_preference.
read_preference & operator=(const read_preference &)
Copy assigns a read_preference.
read_preference(read_preference &&) noexcept
Move constructs a read_preference.
read_preference(read_mode mode, bsoncxx::v_noabi::document::view_or_value tags)
Constructs a new read_preference with tags.
const stdx::optional< bsoncxx::v_noabi::document::view > hedge() const
Gets the current hedge document to be used for the read preference.
read_mode
Determines which members in a replica set are acceptable to read from.
Definition: read_preference.hpp:76
@ 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_preference()
Constructs a new read_preference with read_mode set to k_primary.
read_preference(const read_preference &)
Copy constructs a read_preference.
read_mode mode() const
Returns the current read_mode for this read_preference.
stdx::optional< bsoncxx::v_noabi::document::view > tags() const
Sets or updates the tag set list for this read_preference.
Class representing a MongoDB search index view.
Definition: search_index_view.hpp:23
Class representing a MongoDB connection string URI.
Definition: uri.hpp:47
The top-level namespace for bsoncxx library entities.
Definition: element-fwd.hpp:19
The top-level namespace for mongocxx library entities.
Definition: bulk_write-fwd.hpp:19
Definition: read_preference.hpp:108