Loading...
Searching...
No Matches
replace_one.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/result/replace_one-fwd.hpp> // IWYU pragma: export
//
#include <mongocxx/v1/replace_one_result.hpp> // IWYU pragma: export
#include <cstdint>
#include <utility>
#include <bsoncxx/document/element.hpp>
#include <bsoncxx/stdx/optional.hpp>
#include <bsoncxx/types.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/result/bulk_write.hpp>
#include <mongocxx/config/prelude.hpp>
namespace mongocxx {
namespace v_noabi {
namespace result {
class replace_one {
public:
explicit replace_one(v_noabi::result::bulk_write result) : _result{std::move(result)} {}
/* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE() replace_one(v1::replace_one_result opts);
explicit MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE() operator v1::replace_one_result() const;
v_noabi::result::bulk_write const& result() const {
return _result;
}
std::int32_t matched_count() const {
return _result.matched_count();
}
std::int32_t modified_count() const {
return _result.modified_count();
}
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::element> upserted_id() const {
auto const ids = _result.upserted_ids();
auto const iter = ids.find(0);
if (iter != ids.end()) {
return iter->second;
}
return {};
}
friend bool operator==(replace_one const& lhs, replace_one const& rhs) {
return lhs._result == rhs._result;
}
friend bool operator!=(replace_one const& lhs, replace_one const& rhs) {
return !(lhs == rhs);
}
private:
v_noabi::result::bulk_write _result;
};
} // namespace result
} // namespace v_noabi
} // namespace mongocxx
namespace mongocxx {
namespace v_noabi {
inline v_noabi::result::replace_one from_v1(v1::replace_one_result v) {
return {std::move(v)};
}
inline v1::replace_one_result to_v1(v_noabi::result::replace_one const& v) {
return v1::replace_one_result{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
mongocxx::result::replace_one::replace_one
replace_one(v_noabi::result::bulk_write result)
Definition replace_one.hpp:46
mongocxx::v1::replace_one_result
The result of a "replaceOne" operation.
Definition replace_one_result.hpp:44
mongocxx::v_noabi::result::bulk_write
The result of a MongoDB bulk write operation.
Definition bulk_write.hpp:43
mongocxx::v_noabi::result::replace_one
The result of a MongoDB replaceOne operation.
Definition replace_one.hpp:41
mongocxx::v_noabi::result::replace_one::upserted_id
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::element > upserted_id() const
Gets the id of the upserted document.
Definition replace_one.hpp:90
mongocxx::v_noabi::result::replace_one::modified_count
std::int32_t modified_count() const
Gets the number of documents that were modified during this operation.
Definition replace_one.hpp:81
mongocxx::v_noabi::result::replace_one::replace_one_result
operator v1::replace_one_result() const
Convert to the mongocxx::v1 equivalent.
mongocxx::v_noabi::result::replace_one::result
v_noabi::result::bulk_write const & result() const
Returns the bulk write result for this replace_one operation.
Definition replace_one.hpp:63
mongocxx::v_noabi::result::replace_one::matched_count
std::int32_t matched_count() const
Gets the number of documents that were matched during this operation.
Definition replace_one.hpp:72
mongocxx::v_noabi::result::replace_one::replace_one
replace_one(v_noabi::result::bulk_write result)
Definition replace_one.hpp:46
element.hpp
Provides bsoncxx::v_noabi::document::element.
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.
mongocxx::v1
Declares entities whose ABI stability is guaranteed for documented symbols.
mongocxx::v_noabi::result
Declares entities representing the result of various commands.
mongocxx::v_noabi
Declares entities whose ABI stability is NOT guaranteed.
mongocxx::v_noabi::operator==
bool operator==(std::string str, hint const &hint)
Convenience methods to compare against an index name.
Definition hint.hpp:138
mongocxx::v_noabi::operator!=
bool operator!=(hint const &hint, std::string str)
Convenience methods to compare against an index name.
Definition hint.hpp:143
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.
replace_one_result.hpp
Provides mongocxx::v1::replace_one_result.
replace_one-fwd.hpp
Declares mongocxx::v_noabi::result::replace_one.
types.hpp
Provides entities used to represent BSON types.
optional.hpp
Provides std::optional-related polyfills for library API usage.
bulk_write.hpp
Provides mongocxx::v_noabi::result::bulk_write.