MongoDB C++ Driver current
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 {
31inline namespace v_noabi {
32class client;
33class collection;
34class database;
35class search_index_view;
36class uri;
37
38namespace events {
39class topology_description;
40}
41
42namespace options {
43class transaction;
44}
45
67class MONGOCXX_API read_preference {
68 public:
80 enum class read_mode : std::uint8_t {
84 k_primary,
85
89 k_primary_preferred,
90
94 k_secondary,
95
99 k_secondary_preferred,
100
104 k_nearest
105 };
106
111
112 struct deprecated_tag {};
113
122 MONGOCXX_DEPRECATED read_preference(read_mode mode);
124
137 MONGOCXX_DEPRECATED read_preference(read_mode mode, bsoncxx::document::view_or_value tags);
138 read_preference(read_mode mode, bsoncxx::document::view_or_value tags, deprecated_tag);
139
144
149
154
158 read_preference& operator=(read_preference&&) noexcept;
159
164
176
182 read_mode mode() const;
183
196 read_preference& tags(bsoncxx::document::view_or_value tag_set_list);
197
210 read_preference& tags(bsoncxx::array::view_or_value tag_set_list);
211
219 stdx::optional<bsoncxx::document::view> tags() const;
220
251 read_preference& max_staleness(std::chrono::seconds max_staleness);
252
258 stdx::optional<std::chrono::seconds> max_staleness() const;
259
278 read_preference& hedge(bsoncxx::document::view_or_value hedge);
279
285 const stdx::optional<bsoncxx::document::view> hedge() const;
286
287 private:
288 friend class client;
289 friend class collection;
290 friend class database;
291 friend class search_index_view;
292 friend class uri;
293
294 friend class events::topology_description;
295 friend class options::transaction;
296
304 friend MONGOCXX_API bool MONGOCXX_CALL operator==(const read_preference&,
305 const read_preference&);
306 friend MONGOCXX_API bool MONGOCXX_CALL operator!=(const read_preference&,
307 const read_preference&);
311
312 class MONGOCXX_PRIVATE impl;
313
314 MONGOCXX_PRIVATE read_preference(std::unique_ptr<impl>&& implementation);
315
316 std::unique_ptr<impl> _impl;
317};
318
319} // namespace v_noabi
320} // namespace mongocxx
321
322#include <mongocxx/config/postlude.hpp>
Class representing a client connection to MongoDB.
Definition client.hpp:54
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:67
read_preference(read_mode mode)
Constructs a new read_preference.
read_preference(read_preference &&) noexcept
Move constructs a read_preference.
read_preference(read_mode mode, bsoncxx::document::view_or_value tags)
Constructs a new read_preference with tags.
read_mode
Determines which members in a replica set are acceptable to read from.
Definition read_preference.hpp:80
read_preference()
Constructs a new read_preference with read_mode set to k_primary.
read_preference & operator=(const read_preference &)
Copy assigns a read_preference.
read_preference(const read_preference &)
Copy constructs a read_preference.
Class representing a MongoDB search index view.
Definition search_index_view.hpp:19
Class representing a MongoDB connection string URI.
Definition uri.hpp:42
The top-level namespace for bsoncxx library entities.
Definition element.hpp:24
The top-level namespace for mongocxx library entities.
Definition bulk_write.hpp:24
Definition read_preference.hpp:112