Loading...
Searching...
No Matches
insert.hpp
Go to the documentation of this file.
// Copyright 2009-present MongoDB, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <mongocxx/options/insert-fwd.hpp> // IWYU pragma: export
//
#include <bsoncxx/v1/types/value.hpp>
#include <mongocxx/v1/insert_many_options.hpp> // IWYU pragma: export
#include <mongocxx/v1/insert_one_options.hpp> // IWYU pragma: export
#include <utility>
#include <bsoncxx/document/view.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <bsoncxx/stdx/optional.hpp>
#include <bsoncxx/types/bson_value/view.hpp>
#include <bsoncxx/types/bson_value/view_or_value.hpp>
#include <mongocxx/read_concern.hpp>
#include <mongocxx/write_concern.hpp>
#include <mongocxx/config/prelude.hpp>
namespace mongocxx {
namespace v_noabi {
namespace options {
class insert {
public:
insert() = default;
/* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE() insert(v1::insert_many_options opts);
/* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE() insert(v1::insert_one_options opts);
explicit operator v1::insert_many_options() const {
using bsoncxx::v_noabi::to_v1;
using mongocxx::v_noabi::to_v1;
v1::insert_many_options ret;
if (_read_concern) {
ret.read_concern(to_v1(*_read_concern));
}
if (_write_concern) {
ret.write_concern(to_v1(*_write_concern));
}
if (_bypass_document_validation) {
ret.bypass_document_validation(*_bypass_document_validation);
}
if (_ordered) {
ret.ordered(*_ordered);
}
if (_comment) {
ret.comment(bsoncxx::v1::types::value{to_v1(*_comment)});
}
return ret;
}
explicit operator v1::insert_one_options() const {
using bsoncxx::v_noabi::to_v1;
using mongocxx::v_noabi::to_v1;
v1::insert_one_options ret;
if (_read_concern) {
ret.read_concern(to_v1(*_read_concern));
}
if (_write_concern) {
ret.write_concern(to_v1(*_write_concern));
}
if (_bypass_document_validation) {
ret.bypass_document_validation(*_bypass_document_validation);
}
if (_comment) {
ret.comment(bsoncxx::v1::types::value{to_v1(*_comment)});
}
return ret;
}
insert& bypass_document_validation(bool bypass_document_validation) {
_bypass_document_validation = bypass_document_validation;
return *this;
}
bsoncxx::v_noabi::stdx::optional<bool> const& bypass_document_validation() const {
return _bypass_document_validation;
}
insert& read_concern(v_noabi::read_concern rc) {
_read_concern = std::move(rc);
return *this;
}
bsoncxx::v_noabi::stdx::optional<v_noabi::read_concern> const& read_concern() const {
return _read_concern;
}
insert& write_concern(v_noabi::write_concern wc) {
_write_concern = std::move(wc);
return *this;
}
bsoncxx::v_noabi::stdx::optional<v_noabi::write_concern> const& write_concern() const {
return _write_concern;
}
insert& ordered(bool ordered) {
_ordered = ordered;
return *this;
}
bsoncxx::v_noabi::stdx::optional<bool> const& ordered() const {
return _ordered;
}
insert& comment(bsoncxx::v_noabi::types::bson_value::view_or_value comment) {
_comment = std::move(comment);
return *this;
}
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::types::bson_value::view_or_value> const& comment() const {
return _comment;
}
private:
bsoncxx::v_noabi::stdx::optional<v_noabi::read_concern> _read_concern;
bsoncxx::v_noabi::stdx::optional<v_noabi::write_concern> _write_concern;
bsoncxx::v_noabi::stdx::optional<bool> _ordered;
bsoncxx::v_noabi::stdx::optional<bool> _bypass_document_validation;
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::types::bson_value::view_or_value> _comment;
};
} // namespace options
} // namespace v_noabi
} // namespace mongocxx
namespace mongocxx {
namespace v_noabi {
inline v_noabi::options::insert from_v1(v1::insert_many_options v) {
return {std::move(v)};
}
inline v_noabi::options::insert from_v1(v1::insert_one_options v) {
return {std::move(v)};
}
// Ambiguous whether `v_noabi::options::insert` should be converted to `v1::insert_many_options` or
// `v1::insert_one_options`. Require users to explicitly cast to the expected type instead.
//
// v1::insert_many_options to_v1(v_noabi::options::insert const& v);
// v1::insert_one_options to_v1(v_noabi::options::insert const& v);
} // namespace v_noabi
} // namespace mongocxx
#include <mongocxx/config/postlude.hpp>
bsoncxx::v1::stdx::optional
A polyfill for std::optional<T>.
Definition optional.hpp:799
bsoncxx::v1::types::value
A union of BSON type values.
Definition value.hpp:52
mongocxx::options::insert::insert
insert()=default
Default initialization.
mongocxx::v1::insert_many_options
Options for an "insertMany" operation.
Definition insert_many_options.hpp:49
mongocxx::v1::insert_many_options::read_concern
insert_many_options & read_concern(v1::read_concern v)
Set the "readConcern" field.
mongocxx::v1::insert_many_options::write_concern
insert_many_options & write_concern(v1::write_concern v)
Set the "writeConcern" field.
mongocxx::v1::insert_many_options::bypass_document_validation
insert_many_options & bypass_document_validation(bool v)
Set the "bypassDocumentValidation" field.
mongocxx::v1::insert_many_options::comment
insert_many_options & comment(bsoncxx::v1::types::value v)
Set the "comment" field.
mongocxx::v1::insert_many_options::ordered
insert_many_options & ordered(bool v)
Set the "ordered" field.
mongocxx::v1::insert_one_options
Options for an "insertOne" operation.
Definition insert_one_options.hpp:48
mongocxx::v1::insert_one_options::read_concern
insert_one_options & read_concern(v1::read_concern v)
Set the "readConcern" field.
mongocxx::v1::insert_one_options::comment
insert_one_options & comment(bsoncxx::v1::types::value v)
Set the "comment" field.
mongocxx::v1::insert_one_options::write_concern
insert_one_options & write_concern(v1::write_concern v)
Set the "writeConcern" field.
mongocxx::v1::insert_one_options::bypass_document_validation
insert_one_options & bypass_document_validation(bool v)
Set the "bypassDocumentValidation" field.
mongocxx::v_noabi::options::insert
Used by mongocxx::v_noabi::collection.
Definition insert.hpp:45
mongocxx::v_noabi::options::insert::insert_one_options
operator v1::insert_one_options() const
Convert to the mongocxx::v1 equivalent.
Definition insert.hpp:99
mongocxx::v_noabi::options::insert::insert_many_options
operator v1::insert_many_options() const
Convert to the mongocxx::v1 equivalent.
Definition insert.hpp:65
mongocxx::v_noabi::options::insert::insert
insert()=default
Default initialization.
mongocxx::v_noabi::options::insert::write_concern
insert & write_concern(v_noabi::write_concern wc)
Sets the write_concern for this operation.
Definition insert.hpp:196
mongocxx::v_noabi::options::insert::comment
insert & comment(bsoncxx::v_noabi::types::bson_value::view_or_value comment)
Sets the comment for this operation.
Definition insert.hpp:261
mongocxx::v_noabi::options::insert::ordered
bsoncxx::v_noabi::stdx::optional< bool > const & ordered() const
The current ordered value for this operation.
Definition insert.hpp:244
mongocxx::v_noabi::options::insert::read_concern
bsoncxx::v_noabi::stdx::optional< v_noabi::read_concern > const & read_concern() const
The current read_concern for this operation.
Definition insert.hpp:179
mongocxx::v_noabi::options::insert::bypass_document_validation
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
mongocxx::v_noabi::options::insert::comment
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
mongocxx::v_noabi::options::insert::ordered
insert & ordered(bool ordered)
Definition insert.hpp:231
mongocxx::v_noabi::options::insert::write_concern
bsoncxx::v_noabi::stdx::optional< v_noabi::write_concern > const & write_concern() const
The current write_concern for this operation.
Definition insert.hpp:209
mongocxx::v_noabi::options::insert::read_concern
insert & read_concern(v_noabi::read_concern rc)
Sets the read_concern for this operation.
Definition insert.hpp:166
mongocxx::v_noabi::options::insert::bypass_document_validation
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
mongocxx::v_noabi::read_concern
Controls the consistency and isolation properties of data read from replica sets and sharded clusters...
Definition read_concern.hpp:54
mongocxx::v_noabi::write_concern
The level of acknowledgment requested for write operations to a MongoDB server.
Definition write_concern.hpp:54
insert-fwd.hpp
Declares mongocxx::v_noabi::options::insert.
insert_many_options.hpp
Provides mongocxx::v1::insert_many_options.
insert_one_options.hpp
Provides mongocxx::v1::insert_one_options.
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE
#define MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(...)
Equivalent to MONGOCXX_ABI_EXPORT_UNSTABLE with MONGOCXX_ABI_CDECL.
Definition config.hpp:28
postlude.hpp
The mongocxx v_noabi macro guard postlude header.
prelude.hpp
The mongocxx v_noabi macro guard prelude header.
bsoncxx::v_noabi::types::bson_value::view_or_value
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
bsoncxx::v_noabi::to_v1
v1::element::view to_v1(v_noabi::array::element const &v)
Convert to the bsoncxx::v1 equivalent of v.
Definition element.hpp:132
mongocxx::v1
Declares entities whose ABI stability is guaranteed for documented symbols.
mongocxx::v_noabi::options
Declares entities representing options to use with various commands.
mongocxx::v_noabi
Declares entities whose ABI stability is NOT guaranteed.
mongocxx::v_noabi::to_v1
v1::bulk_write to_v1(v_noabi::bulk_write v)
Convert to the mongocxx::v1 equivalent of v.
Definition bulk_write.hpp:162
mongocxx::v_noabi::from_v1
v_noabi::bulk_write from_v1(v1::bulk_write v)
Convert to the mongocxx::v_noabi equivalent of v.
Definition bulk_write.hpp:155
mongocxx
The top-level namespace within which all mongocxx library entities are declared.
view_or_value.hpp
Provides bsoncxx::v_noabi::types::bson_value::view_or_value.
value.hpp
Provides bsoncxx::v1::types::value.
view.hpp
Provides bsoncxx::v_noabi::document::view.
optional.hpp
Provides std::optional-related polyfills for library API usage.
view.hpp
Provides bsoncxx::v_noabi::types::bson_value::view.
read_concern.hpp
Provides mongocxx::v_noabi::read_concern.
write_concern.hpp
Provides mongocxx::v_noabi::write_concern.