MongoDB C++ Driver  mongocxx-3.10.2
insert_many.hpp
1 // Copyright 2014 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 <cstdint>
18 #include <map>
19 
20 #include <mongocxx/collection-fwd.hpp>
21 #include <mongocxx/result/insert_many-fwd.hpp>
22 
23 #include <bsoncxx/array/value.hpp>
24 #include <bsoncxx/types.hpp>
25 #include <mongocxx/result/bulk_write.hpp>
26 
27 #include <mongocxx/config/prelude.hpp>
28 
29 namespace mongocxx {
30 namespace v_noabi {
31 namespace result {
32 
37 class insert_many {
38  public:
39  using id_map = std::map<std::size_t, bsoncxx::v_noabi::document::element>;
40 
42 
43  insert_many(const insert_many&);
44  insert_many(insert_many&&) = default;
45 
46  insert_many& operator=(const insert_many&);
47  insert_many& operator=(insert_many&&) = default;
48 
54  const result::bulk_write& result() const;
55 
61  std::int32_t inserted_count() const;
62 
70  id_map inserted_ids() const;
71 
72  private:
73  friend ::mongocxx::v_noabi::collection;
74 
75  // Construct _inserted_ids from _inserted_ids_owned
76  MONGOCXX_PRIVATE void _buildInsertedIds();
77 
78  result::bulk_write _result;
79 
80  // Array containing documents with the values of the _id field for the inserted documents. This
81  // array is in the following format: [{"_id": ...}, {"_id": ...}, ...].
82  bsoncxx::v_noabi::array::value _inserted_ids_owned;
83 
84  // Points into _inserted_ids_owned.
85  id_map _inserted_ids;
86 
87  friend MONGOCXX_API bool MONGOCXX_CALL operator==(const insert_many&, const insert_many&);
88  friend MONGOCXX_API bool MONGOCXX_CALL operator!=(const insert_many&, const insert_many&);
89 };
90 
91 } // namespace result
92 } // namespace v_noabi
93 } // namespace mongocxx
94 
95 #include <mongocxx/config/postlude.hpp>
A read-only BSON array that owns its underlying buffer.
Definition: value.hpp:36
Class representing the result of a MongoDB bulk write operation.
Definition: bulk_write.hpp:36
Class representing the result of a MongoDB insert many operation (executed as a bulk write).
Definition: insert_many.hpp:37
std::int32_t inserted_count() const
Gets the number of documents that were inserted during this operation.
id_map inserted_ids() const
Gets the _ids of the inserted documents.
const result::bulk_write & result() const
Returns the bulk write result for this insert many operation.
The top-level namespace for mongocxx library entities.
Definition: bulk_write-fwd.hpp:19