MongoDB C++ Driver  mongocxx-3.0.3
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 <bsoncxx/array/value.hpp>
21 #include <bsoncxx/types.hpp>
22 #include <mongocxx/result/bulk_write.hpp>
23 
24 #include <mongocxx/config/prelude.hpp>
25 
26 namespace mongocxx {
27 MONGOCXX_INLINE_NAMESPACE_BEGIN
28 
29 class collection;
30 class insert_many_builder;
31 
32 namespace result {
33 
38 class MONGOCXX_API insert_many {
39  public:
40  using id_map = std::map<std::size_t, bsoncxx::document::element>;
41 
47  const result::bulk_write& result() const;
48 
54  std::int32_t inserted_count() const;
55 
63  id_map inserted_ids();
64 
65  private:
66  friend collection;
67  friend insert_many_builder;
68 
69  MONGOCXX_PRIVATE insert_many(result::bulk_write result, bsoncxx::array::view inserted_ids);
70 
71  result::bulk_write _result;
72 
73  // Array containing documents with the values of the _id field for the inserted documents. This
74  // array is in the following format: [{"_id": ...}, {"_id": ...}, ...].
75  bsoncxx::array::value _inserted_ids_owned;
76 
77  // Points into _inserted_ids_owned.
78  id_map _inserted_ids;
79 };
80 
81 } // namespace result
82 MONGOCXX_INLINE_NAMESPACE_END
83 } // namespace mongocxx
84 
85 #include <mongocxx/config/postlude.hpp>
Definition: bulk_write.hpp:22
A read-only BSON array that owns its underlying buffer.
Definition: value.hpp:34
Class to build an insert_many bulk write operation.
Definition: insert_many_builder.hpp:34
Class representing the result of a MongoDB insert many operation (executed as a bulk write)...
Definition: insert_many.hpp:38
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33
Class representing the result of a MongoDB bulk write operation.
Definition: bulk_write.hpp:34
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:74