MongoDB C++ Driver 4.2.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
34
36
37namespace mongocxx {
38namespace v_noabi {
39namespace options {
40
44class insert {
45 public:
49 insert() = default;
50
55
59 /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() insert(v1::insert_one_options opts);
60
64 explicit operator v1::insert_many_options() const {
67
69
70 if (_write_concern) {
71 ret.write_concern(to_v1(*_write_concern));
72 }
73
74 if (_bypass_document_validation) {
75 ret.bypass_document_validation(*_bypass_document_validation);
76 }
77
78 if (_ordered) {
79 ret.ordered(*_ordered);
80 }
81
82 if (_comment) {
84 }
85
86 return ret;
87 }
88
94 explicit operator v1::insert_one_options() const {
97
99
100 if (_write_concern) {
101 ret.write_concern(to_v1(*_write_concern));
102 }
103
104 if (_bypass_document_validation) {
105 ret.bypass_document_validation(*_bypass_document_validation);
106 }
107
108 if (_comment) {
109 ret.comment(bsoncxx::v1::types::value{to_v1(*_comment)});
110 }
111
112 return ret;
113 }
114
131 _bypass_document_validation = bypass_document_validation;
132 return *this;
133 }
134
141 return _bypass_document_validation;
142 }
143
158 _write_concern = std::move(wc);
159 return *this;
160 }
161
171 return _write_concern;
172 }
173
193 _ordered = ordered;
194 return *this;
195 }
196
206 return _ordered;
207 }
208
223 _comment = std::move(comment);
224 return *this;
225 }
226
238
239 private:
242 bsoncxx::v_noabi::stdx::optional<bool> _bypass_document_validation;
244};
245
246} // namespace options
247} // namespace v_noabi
248} // namespace mongocxx
249
250namespace mongocxx {
251namespace v_noabi {
252
257 return {std::move(v)};
258}
259
266 return {std::move(v)};
267}
268
269// Ambiguous whether `v_noabi::options::insert` should be converted to `v1::insert_many_options` or
270// `v1::insert_one_options`. Require users to explicitly cast to the expected type instead.
271//
272// v1::insert_many_options to_v1(v_noabi::options::insert const& v);
273// v1::insert_one_options to_v1(v_noabi::options::insert const& v);
274
275} // namespace v_noabi
276} // namespace mongocxx
277
279
A polyfill for std::optional<T>.
Definition optional.hpp:799
A union of BSON type values.
Definition value.hpp:54
insert()=default
Default initialization.
Options for an "insertMany" operation.
Definition insert_many_options.hpp:49
insert_many_options & comment(bsoncxx::v1::types::value comment)
Set the "comment" field.
insert_many_options & write_concern(v1::write_concern wc)
Set the "write_concern" field.
insert_many_options & ordered(bool ordered)
Set the "ordered" field.
insert_many_options & bypass_document_validation(bool bypass_document_validation)
Set the "bypass_document_validation" field.
Options for an "insertOne" operation.
Definition insert_one_options.hpp:48
insert_one_options & comment(bsoncxx::v1::types::value comment)
Set the "comment" field.
insert_one_options & bypass_document_validation(bool bypass_document_validation)
Set the "bypassDocumentValidation" field.
insert_one_options & write_concern(v1::write_concern wc)
Set the "writeConcern" field.
Used by mongocxx::v_noabi::collection.
Definition insert.hpp:44
operator v1::insert_one_options() const
Convert to the mongocxx::v1 equivalent.
Definition insert.hpp:94
operator v1::insert_many_options() const
Convert to the mongocxx::v1 equivalent.
Definition insert.hpp:64
insert()=default
Default initialization.
insert & write_concern(v_noabi::write_concern wc)
Sets the write_concern for this operation.
Definition insert.hpp:157
insert & comment(bsoncxx::v_noabi::types::bson_value::view_or_value comment)
Sets the comment for this operation.
Definition insert.hpp:222
bsoncxx::v_noabi::stdx::optional< bool > const & ordered() const
The current ordered value for this operation.
Definition insert.hpp:205
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:130
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:235
insert & ordered(bool ordered)
Definition insert.hpp:192
bsoncxx::v_noabi::stdx::optional< v_noabi::write_concern > const & write_concern() const
The current write_concern for this operation.
Definition insert.hpp:170
bsoncxx::v_noabi::stdx::optional< bool > const & bypass_document_validation() const
Gets the current value of the bypass_document_validation option.
Definition insert.hpp:140
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(...)
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<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::write_concern.