MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
update.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/update-fwd.hpp> // IWYU pragma: export
18
19//
20
21#include <mongocxx/v1/update_many_result.hpp> // IWYU pragma: export
22#include <mongocxx/v1/update_one_result.hpp> // IWYU pragma: export
23
24#include <cstdint>
25#include <utility>
26
29#include <bsoncxx/types.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
30
32
34
35namespace mongocxx {
36namespace v_noabi {
37namespace result {
38
42class update {
43 public:
47 explicit update(v_noabi::result::bulk_write result) : _result{std::move(result)} {}
48
52 /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() update(v1::update_many_result opts);
53
57 /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() update(v1::update_one_result opts);
58
62 explicit MONGOCXX_ABI_EXPORT_CDECL() operator v1::update_many_result() const;
63
67 explicit MONGOCXX_ABI_EXPORT_CDECL() operator v1::update_one_result() const;
68
74 v_noabi::result::bulk_write const& result() const {
75 return _result;
76 }
77
83 std::int32_t matched_count() const {
84 return _result.matched_count();
85 }
86
91 std::int32_t modified_count() const {
92 return _result.modified_count();
93 }
94
99 std::int32_t upserted_count() const {
100 return _result.upserted_count();
101 }
102
109 auto const ids = _result.upserted_ids();
110 auto const iter = ids.find(0);
111
112 if (iter != ids.end()) {
113 return iter->second;
114 }
115
116 return {};
117 }
118
119 friend bool operator==(update const& lhs, update const& rhs) {
120 return lhs._result == rhs._result;
121 }
122
123 friend bool operator!=(update const& lhs, update const& rhs) {
124 return !(lhs == rhs);
125 }
126
127 private:
129};
130
131} // namespace result
132} // namespace v_noabi
133} // namespace mongocxx
134
135namespace mongocxx {
136namespace v_noabi {
137
142 return {std::move(v)};
143}
144
149 return {std::move(v)};
150}
151
152// Ambiguous whether `v_noabi::result::update` should be converted to `v1::update_many_result` or
153// `v1::update_one_result`. Require users to explicitly cast to the expected type instead.
154//
155// v1::update_many_result to_v1(v_noabi::result::update const& v);
156// v1::update_one_result to_v1(v_noabi::result::update const& v);
157
158} // namespace v_noabi
159} // namespace mongocxx
160
162
A polyfill for std::optional<T>.
Definition optional.hpp:799
update(v_noabi::result::bulk_write result)
Definition update.hpp:47
The result of an "updateMany" operation.
Definition update_many_result.hpp:45
The result of an "updateOne" operation.
Definition update_one_result.hpp:46
The result of a MongoDB bulk write operation.
Definition bulk_write.hpp:43
The result of a MongoDB update operation.
Definition update.hpp:42
std::int32_t matched_count() const
Gets the number of documents that were matched during this operation.
Definition update.hpp:83
std::int32_t modified_count() const
Gets the number of documents that were modified during this operation.
Definition update.hpp:91
update(v_noabi::result::bulk_write result)
Definition update.hpp:47
std::int32_t upserted_count() const
Gets the number of documents that were upserted during this operation.
Definition update.hpp:99
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::element > upserted_id() const
If a document was upserted during this operation, gets the _id of the upserted document.
Definition update.hpp:108
operator v1::update_one_result() const
Convert to the mongocxx::v1 equivalent.
operator v1::update_many_result() const
Convert to the mongocxx::v1 equivalent.
v_noabi::result::bulk_write const & result() const
Returns the bulk write result for this update operation.
Definition update.hpp:74
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
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.
Declares mongocxx::v_noabi::result::update.
Provides entities used to represent BSON types.
Provides mongocxx::v1::update_many_result.
Provides mongocxx::v1::update_one_result.
Provides std::optional-related polyfills for library API usage.
Provides mongocxx::v_noabi::result::bulk_write.