MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
update_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/model/update_one-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_one() for an example of such overloads.
59 //
60 class _empty_doc_tag {};
61
62 public:
67
71 explicit operator v1::bulk_write::update_one() 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 if (_sort) {
95 ret.sort(bsoncxx::v1::document::value{to_v1(_sort->view())});
96 }
97
98 return ret;
99 }
100
111
121 : update_one{std::move(filter), bsoncxx::v_noabi::document::value{update.view_array()}} {}
122
132 : _filter{std::move(filter)} {
133 (void)update;
134 }
135
142 return _filter;
143 }
144
151 return _update;
152 }
153
164 _collation = std::move(collation);
165 return *this;
166 }
167
180
194 _hint = std::move(index_hint);
195 return *this;
196 }
197
204 return _hint;
205 }
206
211 _sort = std::move(sort);
212 return *this;
213 }
214
221
236 _upsert = upsert;
237 return *this;
238 }
239
246 return _upsert;
247 }
248
259 _array_filters = std::move(array_filters);
260 return *this;
261 }
262
275
276 private:
279
285};
286
287} // namespace model
288} // namespace v_noabi
289} // namespace mongocxx
290
291namespace mongocxx {
292namespace v_noabi {
293
298 return {std::move(v)};
299}
300
307
308} // namespace v_noabi
309} // namespace mongocxx
310
312
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_one(v1::bulk_write::update_one op)
Construct with the mongocxx::v1 equivalent.
A single "Update One" write operation.
Definition bulk_write.hpp:210
update_one & array_filters(bsoncxx::v1::array::value v)
Set the "arrayFilters" field.
update_one & upsert(bool v)
Set the "upsert" field.
update_one & sort(bsoncxx::v1::document::value v)
Set the "sort" field.
update_one & collation(bsoncxx::v1::document::value v)
Set the "collation" field.
update_one & hint(v1::hint v)
Set the "hint" 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 a single document.
Definition update_one.hpp:47
bsoncxx::v_noabi::stdx::optional< v_noabi::hint > const & hint() const
Gets the current hint.
Definition update_one.hpp:203
update_one & hint(v_noabi::hint index_hint)
Sets the index to use for this operation.
Definition update_one.hpp:193
update_one & sort(bsoncxx::v_noabi::document::view_or_value sort)
Set the sort option.
Definition update_one.hpp:210
bsoncxx::v_noabi::document::view_or_value const & update() const
Gets the update document.
Definition update_one.hpp:150
update_one(bsoncxx::v_noabi::document::view_or_value filter, std::initializer_list< _empty_doc_tag > update)
Constructs an update operation that will modify a single document matching the filter.
Definition update_one.hpp:131
update_one(bsoncxx::v_noabi::document::view_or_value filter, bsoncxx::v_noabi::document::view_or_value update)
Constructs an update operation that will modify a single document matching the filter.
Definition update_one.hpp:109
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::array::view_or_value > const & array_filters() const
Get array filters for this operation.
Definition update_one.hpp:272
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_one.hpp:177
update_one & collation(bsoncxx::v_noabi::document::view_or_value collation)
Sets the collation for this update operation.
Definition update_one.hpp:163
update_one & array_filters(bsoncxx::v_noabi::array::view_or_value array_filters)
Set array filters for this update operation.
Definition update_one.hpp:258
update_one(v1::bulk_write::update_one op)
Construct with the mongocxx::v1 equivalent.
bsoncxx::v_noabi::stdx::optional< bool > const & upsert() const
Gets the current value of the upsert option.
Definition update_one.hpp:245
bsoncxx::v_noabi::document::view_or_value const & filter() const
Gets the filter.
Definition update_one.hpp:141
update_one & upsert(bool upsert)
Sets the upsert option.
Definition update_one.hpp:235
update_one(bsoncxx::v_noabi::document::view_or_value filter, pipeline const &update)
Constructs an update operation that will modify a single document matching the filter.
Definition update_one.hpp:120
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view_or_value > const & sort() const
Get the current value of the sort option.
Definition update_one.hpp:218
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_one.
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.