MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
insert_one.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/result/insert_one-fwd.hpp> // IWYU pragma: export
18
19//
20
21#include <mongocxx/v1/insert_one_result.hpp> // IWYU pragma: export
22
23#include <utility>
24
25#include <bsoncxx/array/value.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
26#include <bsoncxx/types.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
29
31
33
34namespace mongocxx {
35namespace v_noabi {
36namespace result {
37
41class insert_one {
42 public:
43 ~insert_one() = default;
44
45 insert_one(insert_one&& other) noexcept = default;
46 insert_one& operator=(insert_one&& other) noexcept = default;
47
48 insert_one(insert_one const& other)
49 : _result{other._result}, _inserted_id_owned{other._inserted_id_owned}, _inserted_id{_inserted_id_owned} {}
50
51 insert_one& operator=(insert_one const& other) {
52 if (this != &other) {
53 _result = other._result;
54 _inserted_id_owned = other._inserted_id_owned;
55 _inserted_id = _inserted_id_owned;
56 }
57
58 return *this;
59 }
60
65 : _result{std::move(result)}, _inserted_id_owned{inserted_id}, _inserted_id{_inserted_id_owned} {}
66
70 /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() insert_one(v1::insert_one_result opts);
71
75 explicit MONGOCXX_ABI_EXPORT_CDECL() operator v1::insert_one_result() const;
76
82 v_noabi::result::bulk_write const& result() const {
83 return _result;
84 }
85
92 return _inserted_id;
93 }
94
95 friend bool operator==(insert_one const& lhs, insert_one const& rhs) {
96 return lhs._result == rhs._result && lhs._inserted_id == rhs._inserted_id;
97 }
98
99 friend bool operator!=(insert_one const& lhs, insert_one const& rhs) {
100 return !(lhs == rhs);
101 }
102
103 private:
105 bsoncxx::v_noabi::types::value _inserted_id_owned;
107};
108
109} // namespace result
110} // namespace v_noabi
111} // namespace mongocxx
112
113namespace mongocxx {
114namespace v_noabi {
115
120 return {std::move(v)};
121}
122
129
130} // namespace v_noabi
131} // namespace mongocxx
132
134
A non-owning variant that can contain any BSON type.
Definition view.hpp:62
The result of an "insertOne" operation.
Definition insert_one_result.hpp:45
The result of a MongoDB bulk write operation.
Definition bulk_write.hpp:43
The result of a MongoDB insert operation.
Definition insert_one.hpp:41
insert_one(v_noabi::result::bulk_write result, bsoncxx::v_noabi::types::view inserted_id)
Definition insert_one.hpp:64
bsoncxx::v_noabi::types::bson_value::view const & inserted_id() const
Gets the _id of the inserted document.
Definition insert_one.hpp:91
v_noabi::result::bulk_write const & result() const
Returns the bulk write result for this insert operation.
Definition insert_one.hpp:82
operator v1::insert_one_result() const
Convert to the mongocxx::v1 equivalent.
Provides mongocxx::v1::insert_one_result.
#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::types::bson_value::view view
Equivalent to bsoncxx::v_noabi::types::bson_value::view.
Definition view-fwd.hpp:35
bson_value::value value
Equivalent to bsoncxx::v_noabi::types::bson_value::value.
Definition value-fwd.hpp:35
Declares entities whose ABI stability is guaranteed for documented symbols.
Declares entities representing the result of various commands.
Declares entities whose ABI stability is NOT guaranteed.
bool operator==(std::string str, hint const &hint)
Convenience methods to compare against an index name.
Definition hint.hpp:138
bool operator!=(hint const &hint, std::string str)
Convenience methods to compare against an index name.
Definition hint.hpp:143
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.
Declares mongocxx::v_noabi::result::insert_one.
Provides entities used to represent BSON types.
Provides bsoncxx::v_noabi::array::value.
Provides bsoncxx::v_noabi::types::bson_value::value.
Provides bsoncxx::v_noabi::types::bson_value::view.
Provides mongocxx::v_noabi::result::bulk_write.