MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
replace_one.hpp
Go to the documentation of this file.
1// Copyright 2009-present 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 <mongocxx/result/replace_one-fwd.hpp> // IWYU pragma: export
18
19//
20
21#include <mongocxx/v1/replace_one_result.hpp> // IWYU pragma: export
22
23#include <cstdint>
24#include <utility>
25
28#include <bsoncxx/types.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
29
31
33
34namespace mongocxx {
35namespace v_noabi {
36namespace result {
37
42 public:
46 explicit replace_one(v_noabi::result::bulk_write result) : _result{std::move(result)} {}
47
52
56 explicit MONGOCXX_ABI_EXPORT_CDECL() operator v1::replace_one_result() const;
57
63 v_noabi::result::bulk_write const& result() const {
64 return _result;
65 }
66
72 std::int32_t matched_count() const {
73 return _result.matched_count();
74 }
75
81 std::int32_t modified_count() const {
82 return _result.modified_count();
83 }
84
91 auto const ids = _result.upserted_ids();
92 auto const iter = ids.find(0);
93
94 if (iter != ids.end()) {
95 return iter->second;
96 }
97
98 return {};
99 }
100
101 friend bool operator==(replace_one const& lhs, replace_one const& rhs) {
102 return lhs._result == rhs._result;
103 }
104
105 friend bool operator!=(replace_one const& lhs, replace_one const& rhs) {
106 return !(lhs == rhs);
107 }
108
109 private:
111};
112
113} // namespace result
114} // namespace v_noabi
115} // namespace mongocxx
116
117namespace mongocxx {
118namespace v_noabi {
119
124 return {std::move(v)};
125}
126
133
134} // namespace v_noabi
135} // namespace mongocxx
136
138
A polyfill for std::optional<T>.
Definition optional.hpp:799
replace_one(v_noabi::result::bulk_write result)
Definition replace_one.hpp:46
The result of a "replaceOne" operation.
Definition replace_one_result.hpp:46
The result of a MongoDB bulk write operation.
Definition bulk_write.hpp:43
The result of a MongoDB replaceOne operation.
Definition replace_one.hpp:41
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
std::int32_t modified_count() const
Gets the number of documents that were modified during this operation.
Definition replace_one.hpp:81
operator v1::replace_one_result() const
Convert to the mongocxx::v1 equivalent.
v_noabi::result::bulk_write const & result() const
Returns the bulk write result for this replace_one operation.
Definition replace_one.hpp:63
std::int32_t matched_count() const
Gets the number of documents that were matched during this operation.
Definition replace_one.hpp:72
replace_one(v_noabi::result::bulk_write result)
Definition replace_one.hpp:46
Provides bsoncxx::v_noabi::document::element.
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition export.hpp:52
The mongocxx v_noabi macro guard postlude header.
The mongocxx v_noabi macro guard prelude header.
Declares entities whose ABI stability is guaranteed for documented symbols.
Declares entities representing the result of various commands.
Declares entities whose ABI stability is NOT guaranteed.
bool operator==(std::string str, hint const &hint)
Convenience methods to compare against an index name.
Definition hint.hpp:138
bool operator!=(hint const &hint, std::string str)
Convenience methods to compare against an index name.
Definition hint.hpp:143
v1::bulk_write to_v1(v_noabi::bulk_write v)
Convert to the mongocxx::v1 equivalent of v.
Definition bulk_write.hpp:162
v_noabi::bulk_write from_v1(v1::bulk_write v)
Convert to the mongocxx::v_noabi equivalent of v.
Definition bulk_write.hpp:155
The top-level namespace within which all mongocxx library entities are declared.
Provides mongocxx::v1::replace_one_result.
Declares mongocxx::v_noabi::result::replace_one.
Provides entities used to represent BSON types.
Provides std::optional-related polyfills for library API usage.
Provides mongocxx::v_noabi::result::bulk_write.