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/v1/write_concern-fwd.hpp> // IWYU pragma: export
//
#include <mongocxx/v1/detail/prelude.hpp>
#include <bsoncxx/v1/document/value-fwd.hpp>
#include <bsoncxx/v1/stdx/optional.hpp>
#include <bsoncxx/v1/stdx/string_view.hpp>
#include <mongocxx/v1/config/export.hpp>
#include <chrono>
#include <cstdint>
namespace mongocxx {
namespace v1 {
class write_concern {
private:
void* _impl; // mongoc_write_concern_t
public:
enum class level {
k_default,
k_majority,
k_tag,
k_unacknowledged,
k_acknowledged,
k_unknown,
};
MONGOCXX_ABI_EXPORT_CDECL() ~write_concern();
MONGOCXX_ABI_EXPORT_CDECL() write_concern(write_concern&& other) noexcept;
MONGOCXX_ABI_EXPORT_CDECL(write_concern&) operator=(write_concern&& other) noexcept;
MONGOCXX_ABI_EXPORT_CDECL() write_concern(write_concern const& other);
MONGOCXX_ABI_EXPORT_CDECL(write_concern&) operator=(write_concern const& other);
MONGOCXX_ABI_EXPORT_CDECL() write_concern();
MONGOCXX_ABI_EXPORT_CDECL(write_concern&) acknowledge_level(level v);
MONGOCXX_ABI_EXPORT_CDECL(level) acknowledge_level() const;
write_concern& majority() {
return this->acknowledge_level(level::k_majority);
}
write_concern& majority(std::chrono::milliseconds v) {
return this->acknowledge_level(level::k_majority).timeout(v);
}
MONGOCXX_ABI_EXPORT_CDECL(write_concern&) timeout(std::chrono::milliseconds v);
MONGOCXX_ABI_EXPORT_CDECL(std::chrono::milliseconds) timeout() const;
MONGOCXX_ABI_EXPORT_CDECL(write_concern&) nodes(std::int32_t v);
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) nodes() const;
MONGOCXX_ABI_EXPORT_CDECL(write_concern&) tag(bsoncxx::v1::stdx::string_view v);
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::stdx::string_view>) tag() const;
MONGOCXX_ABI_EXPORT_CDECL(write_concern&) journal(bool j);
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) journal() const;
MONGOCXX_ABI_EXPORT_CDECL(bool) is_acknowledged() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::value) to_document() const;
friend MONGOCXX_ABI_EXPORT_CDECL(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;
private:
/* explicit(false) */ write_concern(void* impl);
};
} // namespace v1
} // namespace mongocxx
#include <mongocxx/v1/detail/postlude.hpp>
bsoncxx::v1::document::value
A BSON document.
Definition value.hpp:44
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
mongocxx::v1::write_concern::acknowledge_level
write_concern & acknowledge_level(level v)
Set the "w" field as to acknowledgement level.
mongocxx::v1::write_concern::timeout
std::chrono::milliseconds timeout() const
Return the current "wtimeout" field.
mongocxx::v1::write_concern::operator!=
friend bool operator!=(write_concern const &lhs, write_concern const &rhs)
Compare equal when all supported fields compare equal.
Definition write_concern.hpp:242
mongocxx::v1::write_concern::journal
bsoncxx::v1::stdx::optional< bool > journal() const
Return the current "j" field.
mongocxx::v1::write_concern::acknowledge_level
level acknowledge_level() const
Return the current "w" field as an acknowledgement level.
mongocxx::v1::write_concern::journal
write_concern & journal(bool j)
Set the "j" field.
mongocxx::v1::write_concern::write_concern
write_concern(write_concern &&other) noexcept
Move constructor.
mongocxx::v1::write_concern::write_concern
write_concern()
Default initialization.
mongocxx::v1::write_concern::to_document
bsoncxx::v1::document::value to_document() const
Return this write concern option as a document.
mongocxx::v1::write_concern::tag
write_concern & tag(bsoncxx::v1::stdx::string_view v)
Set the "w" field to a custom write concern name.
mongocxx::v1::write_concern::majority
write_concern & majority()
Equivalent to this->acknowledge_level(level::k_majority).
Definition write_concern.hpp:159
mongocxx::v1::write_concern::timeout
write_concern & timeout(std::chrono::milliseconds v)
Set the "wtimeout" field.
mongocxx::v1::write_concern::tag
bsoncxx::v1::stdx::optional< bsoncxx::v1::stdx::string_view > tag() const
Return the current "w" value as a custom write concern name.
mongocxx::v1::write_concern::operator==
friend bool operator==(write_concern const &lhs, write_concern const &rhs)
Compare equal when all supported fields compare equal.
mongocxx::v1::write_concern::is_acknowledged
bool is_acknowledged() const
Return true when this write concern requires acknowledgement.
mongocxx::v1::write_concern::nodes
bsoncxx::v1::stdx::optional< std::int32_t > nodes() const
Return the current "w" field as an integer.
mongocxx::v1::write_concern::majority
write_concern & majority(std::chrono::milliseconds v)
Equivalent to this->acknowledge_level(k_majority).timeout(timeout).
Definition write_concern.hpp:166
mongocxx::v1::write_concern::~write_concern
~write_concern()
Destroy this object.
mongocxx::v1::write_concern::nodes
write_concern & nodes(std::int32_t v)
Set the "w" field to an integer.
mongocxx::v1::write_concern::level
level
The write concern level.
Definition write_concern.hpp:58
mongocxx::v1::write_concern::level::k_unacknowledged
@ k_unacknowledged
"w": 0
Definition write_concern.hpp:78
mongocxx::v1::write_concern::level::k_unknown
@ k_unknown
An unknown (unsupported) write concern level.
Definition write_concern.hpp:90
mongocxx::v1::write_concern::level::k_tag
@ k_tag
"w": "<custom write concern name>"
Definition write_concern.hpp:73
mongocxx::v1::write_concern::level::k_acknowledged
@ k_acknowledged
"w": 1
Definition write_concern.hpp:83
mongocxx::v1::write_concern::level::k_majority
@ k_majority
"w": "majority"
Definition write_concern.hpp:68
mongocxx::v1::write_concern::level::k_default
@ k_default
Default MongoDB Read Concerns/Write Concerns (MongoDB Manual)
Definition write_concern.hpp:63
export.hpp
Provides macros to control the set of symbols exported in the ABI.
MONGOCXX_ABI_EXPORT_CDECL
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition export.hpp:52
postlude.hpp
The mongocxx v1 macro guard postlude header.
prelude.hpp
The mongocxx v1 macro guard prelude header.
mongocxx::v1
Declares entities whose ABI stability is guaranteed for documented symbols.
mongocxx
The top-level namespace within which all mongocxx library entities are declared.
value-fwd.hpp
Declares bsoncxx::v1::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.
write_concern-fwd.hpp
Declares mongocxx::v1::write_concern.