MongoDB C++ Driver 4.4.0
Loading...
Searching...
No Matches
insert.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/insert-fwd.hpp> // IWYU pragma: export
18
19//
20
22
23#include <mongocxx/v1/insert_many_options.hpp> // IWYU pragma: export
24#include <mongocxx/v1/insert_one_options.hpp> // IWYU pragma: export
25
26#include <utility>
27
28#include <bsoncxx/document/view.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
32
35
37
38namespace mongocxx {
39namespace v_noabi {
40namespace options {
41
45class insert {
46 public:
50 insert() = default;
51
56
61
65 explicit operator v1::insert_many_options() const {
68
70
71 if (_read_concern) {
72 ret.read_concern(to_v1(*_read_concern));
73 }
74
75 if (_write_concern) {
76 ret.write_concern(to_v1(*_write_concern));
77 }
78
79 if (_bypass_document_validation) {
80 ret.bypass_document_validation(*_bypass_document_validation);
81 }
82
83 if (_ordered) {
84 ret.ordered(*_ordered);
85 }
86
87 if (_comment) {
89 }
90
91 return ret;
92 }
93
99 explicit operator v1::insert_one_options() const {
102
104
105 if (_read_concern) {
106 ret.read_concern(to_v1(*_read_concern));
107 }
108
109 if (_write_concern) {
110 ret.write_concern(to_v1(*_write_concern));
111 }
112
113 if (_bypass_document_validation) {
114 ret.bypass_document_validation(*_bypass_document_validation);
115 }
116
117 if (_comment) {
118 ret.comment(bsoncxx::v1::types::value{to_v1(*_comment)});
119 }
120
121 return ret;
122 }
123
140 _bypass_document_validation = bypass_document_validation;
141 return *this;
142 }
143
150 return _bypass_document_validation;
151 }
152
167 _read_concern = std::move(rc);
168 return *this;
169 }
170
180 return _read_concern;
181 }
182
197 _write_concern = std::move(wc);
198 return *this;
199 }
200
210 return _write_concern;
211 }
212
232 _ordered = ordered;
233 return *this;
234 }
235
245 return _ordered;
246 }
247
262 _comment = std::move(comment);
263 return *this;
264 }
265
277
278 private:
282 bsoncxx::v_noabi::stdx::optional<bool> _bypass_document_validation;
284};
285
286} // namespace options
287} // namespace v_noabi
288} // namespace mongocxx
289
290namespace mongocxx {
291namespace v_noabi {
292
297 return {std::move(v)};
298}
299
306 return {std::move(v)};
307}
308
309// Ambiguous whether `v_noabi::options::insert` should be converted to `v1::insert_many_options` or
310// `v1::insert_one_options`. Require users to explicitly cast to the expected type instead.
311//
312// v1::insert_many_options to_v1(v_noabi::options::insert const& v);
313// v1::insert_one_options to_v1(v_noabi::options::insert const& v);
314
315} // namespace v_noabi
316} // namespace mongocxx
317
319
A polyfill for std::optional<T>.
Definition optional.hpp:799
A union of BSON type values.
Definition value.hpp:52
insert()=default
Default initialization.
Options for an "insertMany" operation.
Definition insert_many_options.hpp:49
insert_many_options & read_concern(v1::read_concern v)
Set the "readConcern" field.
insert_many_options & write_concern(v1::write_concern v)
Set the "writeConcern" field.
insert_many_options & bypass_document_validation(bool v)
Set the "bypassDocumentValidation" field.
insert_many_options & comment(bsoncxx::v1::types::value v)
Set the "comment" field.
insert_many_options & ordered(bool v)
Set the "ordered" field.
Options for an "insertOne" operation.
Definition insert_one_options.hpp:48
insert_one_options & read_concern(v1::read_concern v)
Set the "readConcern" field.
insert_one_options & comment(bsoncxx::v1::types::value v)
Set the "comment" field.
insert_one_options & write_concern(v1::write_concern v)
Set the "writeConcern" field.
insert_one_options & bypass_document_validation(bool v)
Set the "bypassDocumentValidation" field.
Used by mongocxx::v_noabi::collection.
Definition insert.hpp:45
operator v1::insert_one_options() const
Convert to the mongocxx::v1 equivalent.
Definition insert.hpp:99
operator v1::insert_many_options() const
Convert to the mongocxx::v1 equivalent.
Definition insert.hpp:65
insert()=default
Default initialization.
insert & write_concern(v_noabi::write_concern wc)
Sets the write_concern for this operation.
Definition insert.hpp:196
insert & comment(bsoncxx::v_noabi::types::bson_value::view_or_value comment)
Sets the comment for this operation.
Definition insert.hpp:261
bsoncxx::v_noabi::stdx::optional< bool > const & ordered() const
The current ordered value for this operation.
Definition insert.hpp:244
bsoncxx::v_noabi::stdx::optional< v_noabi::read_concern > const & read_concern() const
The current read_concern for this operation.
Definition insert.hpp:179
insert & 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 insert.hpp:139
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::types::bson_value::view_or_value > const & comment() const
The current comment for this operation.
Definition insert.hpp:274
insert & ordered(bool ordered)
Definition insert.hpp:231
bsoncxx::v_noabi::stdx::optional< v_noabi::write_concern > const & write_concern() const
The current write_concern for this operation.
Definition insert.hpp:209
insert & read_concern(v_noabi::read_concern rc)
Sets the read_concern for this operation.
Definition insert.hpp:166
bsoncxx::v_noabi::stdx::optional< bool > const & bypass_document_validation() const
Gets the current value of the bypass_document_validation option.
Definition insert.hpp:149
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
Declares mongocxx::v_noabi::options::insert.
Provides mongocxx::v1::insert_many_options.
Provides mongocxx::v1::insert_one_options.
#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< 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.
Provides bsoncxx::v_noabi::types::bson_value::view_or_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::read_concern.
Provides mongocxx::v_noabi::write_concern.