Loading...
Searching...
No Matches
insert_one.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/result/insert_one-fwd.hpp> // IWYU pragma: export
//
#include <mongocxx/v1/insert_one_result.hpp> // IWYU pragma: export
#include <utility>
#include <bsoncxx/array/value.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <bsoncxx/types.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <bsoncxx/types/bson_value/value.hpp>
#include <bsoncxx/types/bson_value/view.hpp>
#include <mongocxx/result/bulk_write.hpp>
#include <mongocxx/config/prelude.hpp>
namespace mongocxx {
namespace v_noabi {
namespace result {
class insert_one {
public:
~insert_one() = default;
insert_one(insert_one&& other) noexcept = default;
insert_one& operator=(insert_one&& other) noexcept = default;
insert_one(insert_one const& other)
: _result{other._result}, _inserted_id_owned{other._inserted_id_owned}, _inserted_id{_inserted_id_owned} {}
insert_one& operator=(insert_one const& other) {
if (this != &other) {
_result = other._result;
_inserted_id_owned = other._inserted_id_owned;
_inserted_id = _inserted_id_owned;
}
return *this;
}
insert_one(v_noabi::result::bulk_write result, bsoncxx::v_noabi::types::view inserted_id)
: _result{std::move(result)}, _inserted_id_owned{inserted_id}, _inserted_id{_inserted_id_owned} {}
/* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE() insert_one(v1::insert_one_result opts);
explicit MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE() operator v1::insert_one_result() const;
v_noabi::result::bulk_write const& result() const {
return _result;
}
bsoncxx::v_noabi::types::bson_value::view const& inserted_id() const {
return _inserted_id;
}
friend bool operator==(insert_one const& lhs, insert_one const& rhs) {
return lhs._result == rhs._result && lhs._inserted_id == rhs._inserted_id;
}
friend bool operator!=(insert_one const& lhs, insert_one const& rhs) {
return !(lhs == rhs);
}
private:
v_noabi::result::bulk_write _result;
bsoncxx::v_noabi::types::value _inserted_id_owned;
bsoncxx::v_noabi::types::view _inserted_id;
};
} // namespace result
} // namespace v_noabi
} // namespace mongocxx
namespace mongocxx {
namespace v_noabi {
inline v_noabi::result::insert_one from_v1(v1::insert_one_result v) {
return {std::move(v)};
}
inline v1::insert_one_result to_v1(v_noabi::result::insert_one const& v) {
return v1::insert_one_result{v};
}
} // namespace v_noabi
} // namespace mongocxx
#include <mongocxx/config/postlude.hpp>
bsoncxx::v_noabi::types::bson_value::view
A non-owning variant that can contain any BSON type.
Definition view.hpp:62
mongocxx::v1::insert_one_result
The result of an "insertOne" operation.
Definition insert_one_result.hpp:43
mongocxx::v_noabi::result::bulk_write
The result of a MongoDB bulk write operation.
Definition bulk_write.hpp:43
mongocxx::v_noabi::result::insert_one
The result of a MongoDB insert operation.
Definition insert_one.hpp:41
mongocxx::v_noabi::result::insert_one::insert_one
insert_one(v_noabi::result::bulk_write result, bsoncxx::v_noabi::types::view inserted_id)
Definition insert_one.hpp:64
mongocxx::v_noabi::result::insert_one::inserted_id
bsoncxx::v_noabi::types::bson_value::view const & inserted_id() const
Gets the _id of the inserted document.
Definition insert_one.hpp:91
mongocxx::v_noabi::result::insert_one::result
v_noabi::result::bulk_write const & result() const
Returns the bulk write result for this insert operation.
Definition insert_one.hpp:82
mongocxx::v_noabi::result::insert_one::insert_one_result
operator v1::insert_one_result() const
Convert to the mongocxx::v1 equivalent.
insert_one_result.hpp
Provides mongocxx::v1::insert_one_result.
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::view
v_noabi::types::bson_value::view view
Equivalent to bsoncxx::v_noabi::types::bson_value::view.
Definition view-fwd.hpp:35
bsoncxx::v_noabi::types::value
bson_value::value value
Equivalent to bsoncxx::v_noabi::types::bson_value::value.
Definition value-fwd.hpp:35
mongocxx::v1
Declares entities whose ABI stability is guaranteed for documented symbols.
mongocxx::v_noabi::result
Declares entities representing the result of various commands.
mongocxx::v_noabi
Declares entities whose ABI stability is NOT guaranteed.
mongocxx::v_noabi::operator==
bool operator==(std::string str, hint const &hint)
Convenience methods to compare against an index name.
Definition hint.hpp:138
mongocxx::v_noabi::operator!=
bool operator!=(hint const &hint, std::string str)
Convenience methods to compare against an index name.
Definition hint.hpp:143
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.
insert_one-fwd.hpp
Declares mongocxx::v_noabi::result::insert_one.
types.hpp
Provides entities used to represent BSON types.
value.hpp
Provides bsoncxx::v_noabi::array::value.
value.hpp
Provides bsoncxx::v_noabi::types::bson_value::value.
view.hpp
Provides bsoncxx::v_noabi::types::bson_value::view.
bulk_write.hpp
Provides mongocxx::v_noabi::result::bulk_write.