Loading...
Searching...
No Matches
write_concern.hpp
Go to the documentation of this file.
// Copyright 2009-present MongoDB, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <mongocxx/write_concern-fwd.hpp> // IWYU pragma: export
//
#include <mongocxx/v1/write_concern.hpp>
#include <chrono>
#include <cstdint>
#include <memory> // IWYU pragma: keep: backward compatibility, to be removed.
#include <stdexcept> // IWYU pragma: keep: backward compatibility, to be removed.
#include <string>
#include <utility>
#include <mongocxx/bulk_write-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/client-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/collection-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/database-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/options/transaction-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/uri-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <bsoncxx/document/value.hpp>
#include <bsoncxx/stdx/optional.hpp>
#include <bsoncxx/stdx/string_view.hpp>
#include <mongocxx/options/transaction.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/config/prelude.hpp>
namespace mongocxx {
namespace v_noabi {
class write_concern {
private:
v1::write_concern _wc;
public:
enum class level {
k_default,
k_majority,
k_tag,
k_unacknowledged,
k_acknowledged,
};
write_concern() = default;
/* explicit(false) */ write_concern(v1::write_concern rc) : _wc{std::move(rc)} {}
explicit operator v1::write_concern() && {
return std::move(_wc);
}
explicit operator v1::write_concern() const& {
return _wc;
}
void journal(bool journal) {
_wc.journal(journal);
}
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(void) nodes(std::int32_t confirm_from);
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(void) acknowledge_level(level confirm_level);
void majority(std::chrono::milliseconds timeout) {
this->timeout(timeout);
this->acknowledge_level(level::k_majority);
}
void tag(bsoncxx::v_noabi::stdx::string_view tag) {
_wc.tag(tag);
}
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(void) timeout(std::chrono::milliseconds timeout);
bool journal() const {
return _wc.journal().value_or(false);
}
bsoncxx::v_noabi::stdx::optional<std::int32_t> nodes() const {
return _wc.nodes();
}
level acknowledge_level() const {
return static_cast<level>(_wc.acknowledge_level());
}
bsoncxx::v_noabi::stdx::optional<std::string> tag() const {
bsoncxx::v_noabi::stdx::optional<std::string> ret;
if (auto const opt = _wc.tag()) {
ret.emplace(*opt);
}
return ret;
}
bool majority() const {
return _wc.acknowledge_level() == v1::write_concern::level::k_majority;
}
std::chrono::milliseconds timeout() const {
return _wc.timeout();
}
bool is_acknowledged() const {
return _wc.is_acknowledged();
}
bsoncxx::v_noabi::document::value to_document() const {
return bsoncxx::v_noabi::from_v1(_wc.to_document());
}
friend MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(bool) operator==(write_concern const& lhs, write_concern const& rhs);
friend bool operator!=(write_concern const& lhs, write_concern const& rhs) {
return !(lhs == rhs);
}
class internal;
};
inline v_noabi::write_concern from_v1(v1::write_concern v) {
return {std::move(v)};
}
inline v1::write_concern to_v1(v_noabi::write_concern v) {
return v1::write_concern{std::move(v)};
}
} // namespace v_noabi
} // namespace mongocxx
#include <mongocxx/config/postlude.hpp>
bsoncxx::v1::stdx::optional
A polyfill for std::optional<T>.
Definition optional.hpp:799
bsoncxx::v1::stdx::string_view
A polyfill for std::string_view.
Definition string_view.hpp:412
bsoncxx::v_noabi::document::value
A read-only BSON document that owns its underlying buffer.
Definition value.hpp:48
mongocxx::v1::write_concern
Options related to a MongoDB Write Concern.
Definition write_concern.hpp:47
mongocxx::v1::write_concern::level::k_majority
@ k_majority
"w": "majority"
Definition write_concern.hpp:68
mongocxx::v_noabi::write_concern
The level of acknowledgment requested for write operations to a MongoDB server.
Definition write_concern.hpp:54
mongocxx::v_noabi::write_concern::acknowledge_level
level acknowledge_level() const
Gets the current acknowledgment level.
Definition write_concern.hpp:230
mongocxx::v_noabi::write_concern::is_acknowledged
bool is_acknowledged() const
Gets whether this write_concern requires an acknowledged write.
Definition write_concern.hpp:270
mongocxx::v_noabi::write_concern::majority
void majority(std::chrono::milliseconds timeout)
Requires that a majority of the nodes in a replica set acknowledge a write operation before it is con...
Definition write_concern.hpp:168
mongocxx::v_noabi::write_concern::write_concern
write_concern()=default
Constructs a new write_concern.
mongocxx::v_noabi::write_concern::timeout
void timeout(std::chrono::milliseconds timeout)
Sets an upper bound on the time a write concern can take to be satisfied. If the write concern cannot...
mongocxx::v_noabi::write_concern::operator!=
friend bool operator!=(write_concern const &lhs, write_concern const &rhs)
Compares two write_concern objects for (in)-equality.
Definition write_concern.hpp:292
mongocxx::v_noabi::write_concern::timeout
std::chrono::milliseconds timeout() const
Gets the current timeout for this write_concern.
Definition write_concern.hpp:261
mongocxx::v_noabi::write_concern::journal
bool journal() const
Gets the current status of the journal parameter.
Definition write_concern.hpp:203
mongocxx::v_noabi::write_concern::level
level
A class to represent the write concern level for write operations.
Definition write_concern.hpp:66
mongocxx::v_noabi::write_concern::level::k_unacknowledged
@ k_unacknowledged
Represent write concern with w: 0.
Definition write_concern.hpp:70
mongocxx::v_noabi::write_concern::level::k_tag
@ k_tag
Represent write concern with w: <custom write concern name>.
Definition write_concern.hpp:69
mongocxx::v_noabi::write_concern::level::k_acknowledged
@ k_acknowledged
Represent write concern with w: 1.
Definition write_concern.hpp:71
mongocxx::v_noabi::write_concern::level::k_majority
@ k_majority
Represent write concern with w: "majority".
Definition write_concern.hpp:68
mongocxx::v_noabi::write_concern::level::k_default
@ k_default
Represent the implicit default write concern.
Definition write_concern.hpp:67
mongocxx::v_noabi::write_concern::journal
void journal(bool journal)
Sets the journal parameter for this write concern.
Definition write_concern.hpp:111
mongocxx::v_noabi::write_concern::acknowledge_level
void acknowledge_level(level confirm_level)
Sets the acknowledge level.
mongocxx::v_noabi::write_concern::nodes
void nodes(std::int32_t confirm_from)
Sets the number of nodes that are required to acknowledge the write before the operation is considere...
mongocxx::v_noabi::write_concern::to_document
bsoncxx::v_noabi::document::value to_document() const
Gets the document form of this write_concern.
Definition write_concern.hpp:280
mongocxx::v_noabi::write_concern::majority
bool majority() const
Gets whether the majority of nodes is currently required by this write_concern.
Definition write_concern.hpp:252
mongocxx::v_noabi::write_concern::operator==
friend bool operator==(write_concern const &lhs, write_concern const &rhs)
Compares two write_concern objects for (in)-equality.
mongocxx::v_noabi::write_concern::write_concern
write_concern(v1::write_concern rc)
Construct with the mongocxx::v1 equivalent.
Definition write_concern.hpp:82
mongocxx::v_noabi::write_concern::tag
void tag(bsoncxx::v_noabi::stdx::string_view tag)
Sets the name representing the server-side getLastErrorMode entry containing the list of nodes that m...
Definition write_concern.hpp:182
mongocxx::v_noabi::write_concern::tag
bsoncxx::v_noabi::stdx::optional< std::string > tag() const
Gets the current getLastErrorMode that is required by this write_concern.
Definition write_concern.hpp:239
mongocxx::v_noabi::write_concern::nodes
bsoncxx::v_noabi::stdx::optional< std::int32_t > nodes() const
Gets the current number of nodes that this write_concern requires operations to reach....
Definition write_concern.hpp:218
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE
#define MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(...)
Equivalent to MONGOCXX_ABI_EXPORT_UNSTABLE with MONGOCXX_ABI_CDECL.
Definition config.hpp:28
postlude.hpp
The mongocxx v_noabi macro guard postlude header.
prelude.hpp
The mongocxx v_noabi macro guard prelude header.
bsoncxx::v_noabi::from_v1
v_noabi::array::value from_v1(v1::array::value const &v)
Convert from the bsoncxx::v1 equivalent of v.
Definition value.hpp:263
mongocxx::v_noabi
Declares entities whose ABI stability is NOT guaranteed.
mongocxx::v_noabi::to_v1
v1::bulk_write to_v1(v_noabi::bulk_write v)
Convert to the mongocxx::v1 equivalent of v.
Definition bulk_write.hpp:162
mongocxx::v_noabi::from_v1
v_noabi::bulk_write from_v1(v1::bulk_write v)
Convert to the mongocxx::v_noabi equivalent of v.
Definition bulk_write.hpp:155
mongocxx
The top-level namespace within which all mongocxx library entities are declared.
transaction-fwd.hpp
Declares mongocxx::v_noabi::options::transaction.
transaction.hpp
Provides mongocxx::v_noabi::options::transaction.
write_concern.hpp
Provides mongocxx::v1::write_concern.
value.hpp
Provides bsoncxx::v_noabi::document::value.
optional.hpp
Provides std::optional-related polyfills for library API usage.
string_view.hpp
Provides std::string_view-related polyfills for library API usage.
bulk_write-fwd.hpp
Declares mongocxx::v_noabi::bulk_write.
client-fwd.hpp
Declares mongocxx::v_noabi::client.
collection-fwd.hpp
Declares mongocxx::v_noabi::collection.
database-fwd.hpp
Declares mongocxx::v_noabi::database.
uri-fwd.hpp
Declares mongocxx::v_noabi::uri.
write_concern-fwd.hpp
Declares mongocxx::v_noabi::write_concern.