MongoDB C++ Driver  mongocxx-3.6.2
All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
write_concern.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 <stdexcept>
21 
22 #include <bsoncxx/document/value.hpp>
23 #include <bsoncxx/stdx/optional.hpp>
24 #include <bsoncxx/stdx/string_view.hpp>
25 #include <mongocxx/options/transaction.hpp>
26 #include <mongocxx/stdx.hpp>
27 
28 #include <mongocxx/config/prelude.hpp>
29 
30 namespace mongocxx {
31 MONGOCXX_INLINE_NAMESPACE_BEGIN
32 
33 class bulk_write;
34 class client;
35 class collection;
36 class database;
37 class uri;
38 
56 class MONGOCXX_API write_concern {
57  public:
62  enum class level { k_default, k_majority, k_tag, k_unacknowledged, k_acknowledged };
63 
68 
73 
78 
83 
87  write_concern& operator=(write_concern&&) noexcept;
88 
93 
102  void journal(bool journal);
103 
119  void nodes(std::int32_t confirm_from);
120 
139  void acknowledge_level(level confirm_level);
140 
151  void majority(std::chrono::milliseconds timeout);
152 
162  void tag(stdx::string_view tag);
163 
174  void timeout(std::chrono::milliseconds timeout);
175 
181  bool journal() const;
182 
193  stdx::optional<std::int32_t> nodes() const;
194 
202  level acknowledge_level() const;
203 
209  stdx::optional<std::string> tag() const;
210 
216  bool majority() const;
217 
223  std::chrono::milliseconds timeout() const;
224 
230  bool is_acknowledged() const;
231 
238  bsoncxx::document::value to_document() const;
239 
240  private:
241  friend bulk_write;
242  friend client;
243  friend collection;
244  friend database;
245  friend options::transaction;
246  friend uri;
247 
255  friend MONGOCXX_API bool MONGOCXX_CALL operator==(const write_concern&, const write_concern&);
256  friend MONGOCXX_API bool MONGOCXX_CALL operator!=(const write_concern&, const write_concern&);
260 
261  class MONGOCXX_PRIVATE impl;
262 
263  MONGOCXX_PRIVATE write_concern(std::unique_ptr<impl>&& implementation);
264 
265  std::unique_ptr<impl> _impl;
266 };
267 
268 MONGOCXX_INLINE_NAMESPACE_END
269 } // namespace mongocxx
270 
271 #include <mongocxx/config/postlude.hpp>
mongocxx::write_concern::write_concern
write_concern()
Constructs a new write_concern.
mongocxx
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:24
bsoncxx
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24
mongocxx::write_concern
Class representing the server-side requirement for reporting the success of a write operation.
Definition: write_concern.hpp:56
mongocxx::write_concern::operator=
write_concern & operator=(const write_concern &)
Copy assigns a write_concern.
mongocxx::write_concern::write_concern
write_concern(const write_concern &)
Copy constructs a write_concern.
mongocxx::client
Class representing a client connection to MongoDB.
Definition: client.hpp:58
mongocxx::write_concern::write_concern
write_concern(write_concern &&) noexcept
Move constructs a write_concern.
mongocxx::write_concern::level
level
A class to represent the special case values for write_concern::nodes.
Definition: write_concern.hpp:62
mongocxx::uri
Class representing a MongoDB connection string URI.
Definition: uri.hpp:43
mongocxx::bulk_write
Class representing a batch of write operations that can be sent to the server as a group.
Definition: bulk_write.hpp:43
mongocxx::database
Class representing a MongoDB database.
Definition: database.hpp:43
mongocxx::collection
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:81