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/model/replace_one-fwd.hpp> // IWYU pragma: export
18
19//
20
22
23#include <mongocxx/v1/bulk_write.hpp> // IWYU pragma: export
24
25#include <utility>
26
30
31#include <mongocxx/hint.hpp>
32
34
35namespace mongocxx {
36namespace v_noabi {
37namespace model {
38
43 public:
48
52 explicit operator v1::bulk_write::replace_one() const {
55
57 bsoncxx::v1::document::value{to_v1(_filter.view())},
58 bsoncxx::v1::document::value{to_v1(_replacement.view())}};
59
60 if (_collation) {
61 ret.collation(bsoncxx::v1::document::value{to_v1(_collation->view())});
62 }
63
64 if (_upsert) {
65 ret.upsert(*_upsert);
66 }
67
68 if (_hint) {
69 ret.hint(to_v1(*_hint));
70 }
71
72 if (_sort) {
73 ret.sort(bsoncxx::v1::document::value{to_v1(_sort->view())});
74 }
75
76 return ret;
77 }
78
89
96 return _filter;
97 }
98
105 return _replacement;
106 }
107
118 _collation = std::move(collation);
119 return *this;
120 }
121
134
149 _upsert = upsert;
150 return *this;
151 }
152
159 return _upsert;
160 }
161
176 _hint = std::move(index_hint);
177 return *this;
178 }
179
186 return _hint;
187 }
188
193 _sort = std::move(sort);
194 return *this;
195 }
196
203
204 private:
207
212};
213
214} // namespace model
215} // namespace v_noabi
216} // namespace mongocxx
217
218namespace mongocxx {
219namespace v_noabi {
220
225 return {std::move(v)};
226}
227
234
235} // namespace v_noabi
236} // namespace mongocxx
237
239
A BSON document.
Definition value.hpp:46
A polyfill for std::optional<T>.
Definition optional.hpp:799
replace_one(v1::bulk_write::replace_one op)
Construct with the mongocxx::v1 equivalent.
A single "Replace One" write operation.
Definition bulk_write.hpp:466
replace_one & collation(bsoncxx::v1::document::value v)
Set the "collation" field.
replace_one & sort(bsoncxx::v1::document::value v)
Set the "sort" field.
replace_one & upsert(bool v)
Set the "upsert" field.
replace_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 replaces a single document.
Definition replace_one.hpp:42
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view_or_value > const & sort() const
Get the current value of the sort option.
Definition replace_one.hpp:200
bsoncxx::v_noabi::document::view_or_value const & filter() const
Gets the filter for replacement.
Definition replace_one.hpp:95
replace_one(v1::bulk_write::replace_one op)
Construct with the mongocxx::v1 equivalent.
replace_one & collation(bsoncxx::v_noabi::document::view_or_value collation)
Sets the collation for this replacement operation.
Definition replace_one.hpp:117
replace_one & hint(v_noabi::hint index_hint)
Sets the index to use for this operation.
Definition replace_one.hpp:175
replace_one & sort(bsoncxx::v_noabi::document::view_or_value sort)
Set the sort option.
Definition replace_one.hpp:192
replace_one(bsoncxx::v_noabi::document::view_or_value filter, bsoncxx::v_noabi::document::view_or_value replacement)
Constructs an update operation that will replace a single document matching the filter.
Definition replace_one.hpp:87
bsoncxx::v_noabi::stdx::optional< v_noabi::hint > const & hint() const
Gets the current hint.
Definition replace_one.hpp:185
bsoncxx::v_noabi::document::view_or_value const & replacement() const
Gets the replacement document.
Definition replace_one.hpp:104
bsoncxx::v_noabi::stdx::optional< bool > const & upsert() const
Gets the current value of the upsert option.
Definition replace_one.hpp:158
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view_or_value > const & collation() const
Gets the collation option for this replacement operation.
Definition replace_one.hpp:131
replace_one & upsert(bool upsert)
Sets the upsert option.
Definition replace_one.hpp:148
Provides bsoncxx::v_noabi::document::view_or_value.
Declares mongocxx::v_noabi::model::replace_one.
#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< 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
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.
Provides entities related to write operations.
Provides bsoncxx::v1::document::value.
Provides bsoncxx::v_noabi::document::view.
Provides std::optional-related polyfills for library API usage.
Provides mongocxx::v_noabi::hint.