MongoDB C++ Driver 4.4.0
Loading...
Searching...
No Matches
replace.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/options/replace-fwd.hpp> // IWYU pragma: export
18
19//
20
23
24#include <mongocxx/v1/replace_one_options.hpp> // IWYU pragma: export
25
26#include <utility>
27
28#include <bsoncxx/array/view_or_value.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
34
35#include <mongocxx/hint.hpp>
38
40
41namespace mongocxx {
42namespace v_noabi {
43namespace options {
44
48class replace {
49 public:
53 replace() = default;
54
59
63 explicit operator v1::replace_one_options() const {
66
68
69 if (_bypass_document_validation) {
70 ret.bypass_document_validation(*_bypass_document_validation);
71 }
72
73 if (_collation) {
74 ret.collation(bsoncxx::v1::document::value{to_v1(_collation->view())});
75 }
76
77 if (_upsert) {
78 ret.upsert(*_upsert);
79 }
80
81 if (_read_concern) {
82 ret.read_concern(to_v1(*_read_concern));
83 }
84
85 if (_write_concern) {
86 ret.write_concern(to_v1(*_write_concern));
87 }
88
89 if (_hint) {
90 ret.hint(to_v1(*_hint));
91 }
92
93 if (_let) {
94 ret.let(bsoncxx::v1::document::value{to_v1(_let->view())});
95 }
96
97 if (_sort) {
98 ret.sort(bsoncxx::v1::document::value{to_v1(_sort->view())});
99 }
100
101 if (_comment) {
102 ret.comment(bsoncxx::v1::types::value{to_v1(_comment->view())});
103 }
104
105 return ret;
106 }
107
124 _bypass_document_validation = bypass_document_validation;
125 return *this;
126 }
127
134 return _bypass_document_validation;
135 }
136
151 _collation = std::move(collation);
152 return *this;
153 }
154
167
185 _upsert = upsert;
186 return *this;
187 }
188
195 return _upsert;
196 }
197
212 _read_concern = std::move(rc);
213 return *this;
214 }
215
226 return _read_concern;
227 }
228
243 _write_concern = std::move(wc);
244 return *this;
245 }
246
257 return _write_concern;
258 }
259
274 _hint = std::move(index_hint);
275 return *this;
276 }
277
284 return _hint;
285 }
286
298 _let = std::move(let);
299 return *this;
300 }
301
311
316 _sort = std::move(sort);
317 return *this;
318 }
319
326
338 _comment = std::move(comment);
339 return *this;
340 }
341
351
352 private:
353 bsoncxx::v_noabi::stdx::optional<bool> _bypass_document_validation;
362};
363
364} // namespace options
365} // namespace v_noabi
366} // namespace mongocxx
367
368namespace mongocxx {
369namespace v_noabi {
370
375 return {std::move(v)};
376}
377
384
385} // namespace v_noabi
386} // namespace mongocxx
387
389
Provides bsoncxx::v_noabi::array::view_or_value.
A BSON document.
Definition value.hpp:44
A polyfill for std::optional<T>.
Definition optional.hpp:799
A union of BSON type values.
Definition value.hpp:52
replace()=default
Default initialization.
Options for a "replaceOne" operation.
Definition replace_one_options.hpp:56
replace_one_options & bypass_document_validation(bool v)
Set the "bypassDocumentValidation" field.
replace_one_options & let(bsoncxx::v1::document::value v)
Set the "let" field.
replace_one_options & read_concern(v1::read_concern v)
Set the "readConcern" field.
replace_one_options & collation(bsoncxx::v1::document::value v)
Set the "collation" field.
replace_one_options & write_concern(v1::write_concern v)
Set the "writeConcern" field.
replace_one_options & sort(bsoncxx::v1::document::value v)
Set the "sort" field.
replace_one_options & upsert(bool v)
Set the "upsert" field.
replace_one_options & hint(v1::hint v)
Set the "hint" field.
replace_one_options & comment(bsoncxx::v1::types::value v)
Set the "comment" field.
The index to "hint" or force a MongoDB server to use when performing a query.
Definition hint.hpp:42
Used by mongocxx::v_noabi::collection.
Definition replace.hpp:48
bsoncxx::v_noabi::stdx::optional< v_noabi::write_concern > const & write_concern() const
The current write_concern for this operation.
Definition replace.hpp:256
replace & sort(bsoncxx::v_noabi::document::view_or_value sort)
Set the sort option.
Definition replace.hpp:315
bsoncxx::v_noabi::stdx::optional< v_noabi::read_concern > const & read_concern() const
The current read_concern for this operation.
Definition replace.hpp:225
replace & collation(bsoncxx::v_noabi::document::view_or_value collation)
Sets the collation for this operation.
Definition replace.hpp:150
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view_or_value > const & collation() const
Retrieves the current collation for this operation.
Definition replace.hpp:164
replace & hint(v_noabi::hint index_hint)
Sets the index to use for this operation.
Definition replace.hpp:273
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view_or_value > const let() const
Gets the current value of the let option.
Definition replace.hpp:308
replace & write_concern(v_noabi::write_concern wc)
Sets the write_concern for this operation.
Definition replace.hpp:242
replace & bypass_document_validation(bool bypass_document_validation)
Sets the bypass_document_validation option. If true, allows the write to opt-out of document level va...
Definition replace.hpp:123
bsoncxx::v_noabi::stdx::optional< v_noabi::hint > const & hint() const
Gets the current hint.
Definition replace.hpp:283
replace & comment(bsoncxx::v_noabi::types::bson_value::view_or_value comment)
Set the value of the comment option.
Definition replace.hpp:337
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::types::bson_value::view_or_value > const comment() const
Gets the current value of the comment option.
Definition replace.hpp:348
operator v1::replace_one_options() const
Convert to the mongocxx::v1 equivalent.
Definition replace.hpp:63
replace()=default
Default initialization.
replace & upsert(bool upsert)
Sets the upsert option.
Definition replace.hpp:184
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.hpp:323
replace & read_concern(v_noabi::read_concern rc)
Sets the read_concern for this operation.
Definition replace.hpp:211
replace & let(bsoncxx::v_noabi::document::view_or_value let)
Set the value of the let option.
Definition replace.hpp:297
bsoncxx::v_noabi::stdx::optional< bool > const & upsert() const
Gets the current value of the upsert option.
Definition replace.hpp:194
bsoncxx::v_noabi::stdx::optional< bool > const & bypass_document_validation() const
Gets the current value of the bypass_document_validation option.
Definition replace.hpp:133
Controls the consistency and isolation properties of data read from replica sets and sharded clusters...
Definition read_concern.hpp:54
The level of acknowledgment requested for write operations to a MongoDB server.
Definition write_concern.hpp:54
Provides bsoncxx::v_noabi::document::view_or_value.
#define MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(...)
Equivalent to MONGOCXX_ABI_EXPORT_UNSTABLE with MONGOCXX_ABI_CDECL.
Definition config.hpp:28
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
v_noabi::view_or_value< view, value > view_or_value
Equivalent to v_noabi::view_or_value<view, value>.
Definition view_or_value.hpp:31
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 options to use with various commands.
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::options::replace.
Provides mongocxx::v1::replace_one_options.
Provides bsoncxx::v_noabi::types::bson_value::view_or_value.
Provides bsoncxx::v1::document::value.
Provides bsoncxx::v1::types::value.
Provides bsoncxx::v_noabi::document::view.
Provides std::optional-related polyfills for library API usage.
Provides bsoncxx::v_noabi::types::bson_value::view.
Provides mongocxx::v_noabi::hint.
Provides mongocxx::v_noabi::read_concern.
Provides mongocxx::v_noabi::write_concern.