Loading...
Searching...
No Matches
insert_many.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_many-fwd.hpp> // IWYU pragma: export
//
#include <mongocxx/v1/insert_many_result.hpp> // IWYU pragma: export
#include <cstddef>
#include <cstdint>
#include <map>
#include <utility>
#include <mongocxx/collection-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <bsoncxx/array/element.hpp>
#include <bsoncxx/array/value.hpp>
#include <bsoncxx/document/element.hpp>
#include <bsoncxx/types.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/result/bulk_write.hpp>
#include <mongocxx/config/prelude.hpp>
namespace mongocxx {
namespace v_noabi {
namespace result {
class insert_many {
public:
using id_map = std::map<std::size_t, bsoncxx::v_noabi::document::element>;
~insert_many() noexcept = default;
insert_many(insert_many&& other) noexcept = default;
insert_many& operator=(insert_many&& other) = default;
insert_many(insert_many const& other) : _result{other._result}, _inserted_ids{other._inserted_ids} {
this->sync_id_map();
}
insert_many& operator=(insert_many const& other) {
if (this != &other) {
_result = other._result;
_inserted_ids = other._inserted_ids;
this->sync_id_map();
}
return *this;
}
/* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE() insert_many(v1::insert_many_result opts);
explicit MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE() operator v1::insert_many_result() const;
insert_many(result::bulk_write result, bsoncxx::v_noabi::array::value inserted_ids)
: _result{std::move(result)}, _inserted_ids{std::move(inserted_ids)} {
this->sync_id_map();
}
v_noabi::result::bulk_write const& result() const {
return _result;
}
std::int32_t inserted_count() const {
return _result.inserted_count();
}
id_map inserted_ids() const {
return _id_map;
}
friend MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(bool) operator==(insert_many const& lhs, insert_many const& rhs);
friend bool operator!=(insert_many const& lhs, insert_many const& rhs) {
return !(lhs == rhs);
}
private:
v_noabi::result::bulk_write _result;
bsoncxx::v_noabi::array::value _inserted_ids;
id_map _id_map;
void sync_id_map() {
std::size_t index = 0;
for (auto const& ele : _inserted_ids) {
// v_noabi::array::element -> v1::element::view -> v_noabi::document::element
_id_map.emplace(index++, bsoncxx::v_noabi::to_v1(ele));
}
}
};
} // namespace result
} // namespace v_noabi
} // namespace mongocxx
namespace mongocxx {
namespace v_noabi {
inline v_noabi::result::insert_many from_v1(v1::insert_many_result v) {
return {std::move(v)};
}
inline v1::insert_many_result to_v1(v_noabi::result::insert_many const& v) {
return v1::insert_many_result{v};
}
} // namespace v_noabi
} // namespace mongocxx
#include <mongocxx/config/postlude.hpp>
element.hpp
Provides bsoncxx::v_noabi::array::element.
bsoncxx::v_noabi::array::value
A read-only BSON array that owns its underlying buffer.
Definition value.hpp:44
mongocxx::v1::insert_many_result
The result of an "insertMany" operation.
Definition insert_many_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_many
The result of a MongoDB insert many operation.
Definition insert_many.hpp:46
mongocxx::v_noabi::result::insert_many::insert_many_result
operator v1::insert_many_result() const
Convert to the mongocxx::v1 equivalent.
mongocxx::v_noabi::result::insert_many::inserted_count
std::int32_t inserted_count() const
Gets the number of documents that were inserted during this operation.
Definition insert_many.hpp:102
mongocxx::v_noabi::result::insert_many::inserted_ids
id_map inserted_ids() const
Gets the _ids of the inserted documents.
Definition insert_many.hpp:113
mongocxx::v_noabi::result::insert_many::result
v_noabi::result::bulk_write const & result() const
Returns the bulk write result for this insert many operation.
Definition insert_many.hpp:93
element.hpp
Provides bsoncxx::v_noabi::document::element.
insert_many-fwd.hpp
Declares mongocxx::v_noabi::result::insert_many.
insert_many_result.hpp
Provides mongocxx::v1::insert_many_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::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
bsoncxx
The top-level namespace within which all bsoncxx library entities are declared.
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.
types.hpp
Provides entities used to represent BSON types.
value.hpp
Provides bsoncxx::v_noabi::array::value.
collection-fwd.hpp
Declares mongocxx::v_noabi::collection.
bulk_write.hpp
Provides mongocxx::v_noabi::result::bulk_write.