MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
update_many.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/model/update_many-fwd.hpp> // IWYU pragma: export
18
19//
20
22
23#include <mongocxx/v1/bulk_write.hpp> // IWYU pragma: export
24
25#include <initializer_list>
26#include <utility>
27
34
35#include <mongocxx/hint.hpp>
36#include <mongocxx/pipeline.hpp>
37
39
40namespace mongocxx {
41namespace v_noabi {
42namespace model {
43
48 //
49 // Utility class supporting the convenience of {} meaning an empty bsoncxx::v_noabi::document.
50 //
51 // Users may not use this class directly.
52 //
53 // In places where driver methods take this class as a parameter, passing {} will
54 // translate to a default-constructed bsoncxx::v_noabi::document::view_or_value,
55 // regardless of other overloads taking other default-constructible types
56 // for that parameter. This class avoids compiler ambiguity with such overloads.
57 //
58 // See update_many() for an example of such overloads.
59 //
60 class _empty_doc_tag {};
61
62 public:
67
71 explicit operator v1::bulk_write::update_many() const {
74
76 bsoncxx::v1::document::value{to_v1(_filter.view())}, bsoncxx::v1::document::value{to_v1(_update.view())}};
77
78 if (_collation) {
79 ret.collation(bsoncxx::v1::document::value{to_v1(_collation->view())});
80 }
81
82 if (_array_filters) {
83 ret.array_filters(bsoncxx::v1::array::value{to_v1(_array_filters->view())});
84 }
85
86 if (_upsert) {
87 ret.upsert(*_upsert);
88 }
89
90 if (_hint) {
91 ret.hint(to_v1(*_hint));
92 }
93
94 return ret;
95 }
96
107
117 : _filter{std::move(filter)}, _update{bsoncxx::v_noabi::document::value{update.view_array()}} {}
118
128 : _filter{std::move(filter)} {
129 (void)update;
130 }
131
138 return _filter;
139 }
140
147 return _update;
148 }
149
160 _collation = std::move(collation);
161 return *this;
162 }
163
176
190 _hint = std::move(index_hint);
191 return *this;
192 }
193
200 return _hint;
201 }
202
217 _upsert = upsert;
218 return *this;
219 }
220
227 return _upsert;
228 }
229
240 _array_filters = std::move(array_filters);
241 return *this;
242 }
243
256
257 private:
260
265};
266
267} // namespace model
268} // namespace v_noabi
269} // namespace mongocxx
270
271namespace mongocxx {
272namespace v_noabi {
273
278 return {std::move(v)};
279}
280
287
288} // namespace v_noabi
289} // namespace mongocxx
290
292
Provides bsoncxx::v_noabi::array::view_or_value.
A BSON array.
Definition value.hpp:41
A BSON document.
Definition value.hpp:46
A polyfill for std::optional<T>.
Definition optional.hpp:799
update_many(v1::bulk_write::update_many op)
Construct with the mongocxx::v1 equivalent.
A single "Update Many" write operation.
Definition bulk_write.hpp:342
update_many & upsert(bool v)
Set the "upsert" field.
update_many & array_filters(bsoncxx::v1::array::value v)
Set the "arrayFilters" field.
update_many & hint(v1::hint v)
Set the "hint" field.
update_many & collation(bsoncxx::v1::document::value v)
Set the "collation" field.
A batch of write operations that can be sent to the server as a group.
Definition bulk_write.hpp:54
The index to "hint" or force a MongoDB server to use when performing a query.
Definition hint.hpp:42
A MongoDB update operation that modifies multiple documents.
Definition update_many.hpp:47
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::array::view_or_value > const & array_filters() const
Get array filters for this operation.
Definition update_many.hpp:253
bsoncxx::v_noabi::stdx::optional< bool > const & upsert() const
Gets the current value of the upsert option.
Definition update_many.hpp:226
update_many(bsoncxx::v_noabi::document::view_or_value filter, std::initializer_list< _empty_doc_tag > update)
Constructs an update operation that will modify all documents matching the filter.
Definition update_many.hpp:127
update_many(bsoncxx::v_noabi::document::view_or_value filter, pipeline const &update)
Constructs an update operation that will modify all documents matching the filter.
Definition update_many.hpp:116
update_many & upsert(bool upsert)
Sets the upsert option.
Definition update_many.hpp:216
update_many(v1::bulk_write::update_many op)
Construct with the mongocxx::v1 equivalent.
bsoncxx::v_noabi::document::view_or_value const & filter() const
Gets the filter.
Definition update_many.hpp:137
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view_or_value > const & collation() const
Gets the collation option for this update operation.
Definition update_many.hpp:173
update_many & hint(v_noabi::hint index_hint)
Sets the index to use for this operation.
Definition update_many.hpp:189
bsoncxx::v_noabi::document::view_or_value const & update() const
Gets the update document.
Definition update_many.hpp:146
update_many(bsoncxx::v_noabi::document::view_or_value filter, bsoncxx::v_noabi::document::view_or_value update)
Constructs an update operation that will modify all documents matching the filter.
Definition update_many.hpp:105
bsoncxx::v_noabi::stdx::optional< v_noabi::hint > const & hint() const
Gets the current hint.
Definition update_many.hpp:199
update_many & array_filters(bsoncxx::v_noabi::array::view_or_value array_filters)
Set array filters for this update operation.
Definition update_many.hpp:239
update_many & collation(bsoncxx::v_noabi::document::view_or_value collation)
Sets the collation for this update operation.
Definition update_many.hpp:159
A MongoDB aggregation pipeline.
Definition pipeline.hpp:45
Provides bsoncxx::v_noabi::document::view_or_value.
#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.
v_noabi::view_or_value< view, value > view_or_value
Equivalent to v_noabi::view_or_value<v_noabi::array::view, v_noabi::array::value>.
Definition view_or_value.hpp:31
v_noabi::view_or_value< v_noabi::document::view, v_noabi::document::value > view_or_value
Equivalent to v_noabi::view_or_value<v_noabi::document::view, v_noabi::document::value>.
Definition view_or_value.hpp:30
v1::element::view to_v1(v_noabi::array::element const &v)
Convert to the bsoncxx::v1 equivalent of v.
Definition element.hpp:132
The top-level namespace within which all bsoncxx library entities are declared.
Declares entities whose ABI stability is guaranteed for documented symbols.
Declares entities representing bulk write operations.
Declares entities whose ABI stability is NOT guaranteed.
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.
Declares mongocxx::v_noabi::model::update_many.
Provides bsoncxx::v1::array::value.
Provides entities related to write operations.
Provides bsoncxx::v_noabi::array::view.
Provides bsoncxx::v_noabi::document::value.
Provides bsoncxx::v_noabi::document::view.
Provides std::optional-related polyfills for library API usage.
Provides mongocxx::v_noabi::hint.
Provides mongocxx::v_noabi::pipeline.