MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
bulk_write.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
18
19//
20
22
26
28
33
35#include <mongocxx/v1/hint.hpp>
38
39#include <cstdint>
40#include <map>
41#include <utility>
42
43namespace mongocxx {
44namespace v1 {
45
56 private:
57 class impl;
58 void* _impl;
59
60 public:
95
96 class insert_one;
97 class update_one;
98 class update_many;
99 class replace_one;
100 class delete_one;
101 class delete_many;
102 class single;
103 class options;
104 class result;
105
110
118
125 MONGOCXX_ABI_EXPORT_CDECL(bulk_write&) operator=(bulk_write&& other) noexcept;
126
130 bulk_write(bulk_write const& other) = delete;
131
135 bulk_write& operator=(bulk_write const& other) = delete;
136
141
148
158
159 class internal;
160
161 private:
162 /* explicit(false) */ bulk_write(void* bulk);
163};
164
174 public:
179
183 /* explicit(false) */ insert_one(bsoncxx::v1::document::value doc) : value{std::move(doc)} {}
184
189 return value;
190 }
191};
192
211 private:
212 class impl;
213 void* _impl;
214
215 public:
222
230
237 MONGOCXX_ABI_EXPORT_CDECL(update_one&) operator=(update_one&& other) noexcept;
238
243
248
255 MONGOCXX_ABI_EXPORT_CDECL() update_one(bsoncxx::v1::document::value filter, bsoncxx::v1::document::value update);
256
264
268 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) filter() const;
269
273 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) update() const;
274
279
283 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view>) collation() const;
284
289
293 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<v1::hint>) hint() const;
294
299
303 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view>) sort() const;
304
309
313 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) upsert() const;
314
319
323 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::array::view>) array_filters() const;
324
325 class internal;
326};
327
343 private:
344 class impl;
345 void* _impl;
346
347 public:
354
362
369 MONGOCXX_ABI_EXPORT_CDECL(update_many&) operator=(update_many&& other) noexcept;
370
375
380
387 MONGOCXX_ABI_EXPORT_CDECL() update_many(bsoncxx::v1::document::value filter, bsoncxx::v1::document::value update);
388
393
397 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) filter() const;
398
402 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) update() const;
403
408
412 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view>) collation() const;
413
418
422 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<v1::hint>) hint() const;
423
428
432 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) upsert() const;
433
438
442 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::array::view>) array_filters() const;
443
444 class internal;
445
446 private:
447 /* explicit(false) */ update_many(void* impl);
448};
449
467 private:
468 class impl;
469 void* _impl;
470
471 public:
478
486
493 MONGOCXX_ABI_EXPORT_CDECL(replace_one&) operator=(replace_one&& other) noexcept;
494
499
504
512 bsoncxx::v1::document::value filter,
513 bsoncxx::v1::document::value replacement);
514
518 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) filter() const;
519
524
529
533 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view>) collation() const;
534
539
543 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<v1::hint>) hint() const;
544
549
553 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view>) sort() const;
554
559
563 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) upsert() const;
564
565 class internal;
566
567 private:
568 /* explicit(false) */ replace_one(void* impl);
569};
570
585 private:
586 class impl;
587 void* _impl;
588
589 public:
596
604
611 MONGOCXX_ABI_EXPORT_CDECL(delete_one&) operator=(delete_one&& other) noexcept;
612
617
622
629 explicit MONGOCXX_ABI_EXPORT_CDECL() delete_one(bsoncxx::v1::document::value filter);
630
634 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) filter() const;
635
640
644 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view>) collation() const;
645
650
654 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<v1::hint>) hint() const;
655
656 class internal;
657
658 private:
659 /* explicit(false) */ delete_one(void* impl);
660};
661
676 private:
677 class impl;
678 void* _impl;
679
680 public:
687
695
702 MONGOCXX_ABI_EXPORT_CDECL(delete_many&) operator=(delete_many&& other) noexcept;
703
708
713
721
725 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) filter() const;
726
731
735 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view>) collation() const;
736
741
745 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<v1::hint>) hint() const;
746
747 class internal;
748
749 private:
750 /* explicit(false) */ delete_many(void* impl);
751};
752
763 private:
764 class impl;
765 void* _impl;
766
767 public:
774
782
789 MONGOCXX_ABI_EXPORT_CDECL(single&) operator=(single&& other) noexcept;
790
795
799 MONGOCXX_ABI_EXPORT_CDECL(single&) operator=(single const& other);
800
805 /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() single(insert_one op);
806 /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() single(update_one op);
807 /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() single(update_many op);
808 /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() single(delete_one op);
809 /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() single(delete_many op);
810 /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() single(replace_one op);
813
818
830
842
854
866
878
890
891 class internal;
892};
893
911 private:
912 class impl;
913 void* _impl;
914
915 public:
922
930
937 MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options&& other) noexcept;
938
943
947 MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options const& other);
948
957
962
967
972
976 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::types::view>) comment() const;
977
982
986 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view>) let() const;
987
992
997
1002
1007
1008 class internal;
1009
1010 private:
1011 /* explicit(false) */ options(void* impl);
1012};
1013
1033 private:
1034 class impl;
1035 void* _impl;
1036
1037 public:
1044
1052
1059 MONGOCXX_ABI_EXPORT_CDECL(result&) operator=(result&& other) noexcept;
1060
1065
1069 MONGOCXX_ABI_EXPORT_CDECL(result&) operator=(result const& other);
1070
1075
1080
1085
1090
1095
1099 using id_map = std::map<std::int64_t, bsoncxx::v1::types::view>;
1100
1107
1112 friend MONGOCXX_ABI_EXPORT_CDECL(bool) operator==(result const& lhs, result const& rhs);
1113
1114 friend bool operator!=(result const& lhs, result const& rhs) {
1115 return !(lhs == rhs);
1116 }
1117
1119
1120 class internal;
1121
1122 private:
1123 /* explicit(false) */ result(void* impl);
1124};
1125
1126} // namespace v1
1127} // namespace mongocxx
1128
1130
A BSON document.
Definition value.hpp:46
A single "Delete Many" write operation.
Definition bulk_write.hpp:675
bsoncxx::v1::document::view filter() const
Return the current "filter" field.
delete_many & collation(bsoncxx::v1::document::value v)
Set the "collation" field.
~delete_many()
Destroy this object.
delete_many(delete_many &&other) noexcept
Move constructor.
delete_many & hint(v1::hint v)
Set the "hint" field.
A single "Delete One" write operation.
Definition bulk_write.hpp:584
bsoncxx::v1::document::view filter() const
Return the current "filter" field.
delete_one & hint(v1::hint v)
Set the "hint" field.
~delete_one()
Destroy this object.
delete_one & collation(bsoncxx::v1::document::value v)
Set the "collation" field.
delete_one(delete_one &&other) noexcept
Move constructor.
A single "Insert One" write operation.
Definition bulk_write.hpp:173
insert_one(bsoncxx::v1::document::value doc)
Initialize with doc.
Definition bulk_write.hpp:183
bsoncxx::v1::document::value const & document() const
Equivalent to this->value.
Definition bulk_write.hpp:188
bsoncxx::v1::document::value value
The document to be inserted.
Definition bulk_write.hpp:178
options & comment(bsoncxx::v1::types::value comment)
Set the "comment" field.
options & let(bsoncxx::v1::document::value let)
Set the "let" field.
options & bypass_document_validation(bool bypass_document_validation)
Set the "bypassDocumentValidation" field.
options(options &&other) noexcept
Move constructor.
options & write_concern(v1::write_concern wc)
Set the "writeConcern" field.
~options()
Destroy this object.
options & ordered(bool ordered)
Set the "ordered" field.
A single "Replace One" write operation.
Definition bulk_write.hpp:466
~replace_one()
Destroy this object.
bsoncxx::v1::document::view filter() const
Return the current "filter" field.
replace_one & collation(bsoncxx::v1::document::value v)
Set the "collation" field.
replace_one & sort(bsoncxx::v1::document::value v)
Set the "sort" field.
replace_one(replace_one &&other) noexcept
Move constructor.
replace_one & upsert(bool v)
Set the "upsert" field.
bsoncxx::v1::document::view replacement() const
Return the current "replacement" field.
replace_one & hint(v1::hint v)
Set the "hint" field.
The result of a write operation.
Definition bulk_write.hpp:1032
std::int64_t matched_count() const
Return the value of the "matchedCount" field.
std::map< std::int64_t, bsoncxx::v1::types::view > id_map
A map from the operation index to the upserted document ID.
Definition bulk_write.hpp:1099
std::int64_t upserted_count() const
Return the value of the "upsertedCount" field.
result(result &&other) noexcept
Move constructor.
id_map upserted_ids() const
Return the "upsertedIds" field as a a map from the operation index to the upserted document ID.
std::int64_t modified_count() const
Return the value of the "modifiedCount" field.
std::int64_t deleted_count() const
Return the value of the "deletedCount" field.
std::int64_t inserted_count() const
Return the value of the "insertedCount" field.
~result()
Destroy this object.
A single write operation.
Definition bulk_write.hpp:762
single(single &&other) noexcept
Move constructor.
replace_one const & get_replace_one() const &
Return this write operation as an mongocxx::v1::bulk_write::replace_one.
update_one const & get_update_one() const &
Return this write operation as an mongocxx::v1::bulk_write::update_one.
v1::bulk_write::type type() const
Return the type of this write operation.
~single()
Destroy this object.
update_many const & get_update_many() const &
Return this write operation as an mongocxx::v1::bulk_write::update_many.
delete_one const & get_delete_one() const &
Return this write operation as an mongocxx::v1::bulk_write::delete_one.
delete_many const & get_delete_many() const &
Return this write operation as an mongocxx::v1::bulk_write::delete_many.
insert_one const & get_insert_one() const &
Return this write operation as an mongocxx::v1::bulk_write::insert_one.
A single "Update Many" write operation.
Definition bulk_write.hpp:342
bsoncxx::v1::document::view update() const
Return the current "update" field.
bsoncxx::v1::document::view filter() const
Return the current "filter" field.
update_many & upsert(bool v)
Set the "upsert" field.
update_many & array_filters(bsoncxx::v1::array::value v)
Set the "arrayFilters" field.
update_many & hint(v1::hint v)
Set the "hint" field.
~update_many()
Destroy this object.
update_many(update_many &&other) noexcept
Move constructor.
update_many & collation(bsoncxx::v1::document::value v)
Set the "collation" field.
A single "Update One" write operation.
Definition bulk_write.hpp:210
update_one(update_one &&other) noexcept
Move constructor.
update_one & array_filters(bsoncxx::v1::array::value v)
Set the "arrayFilters" field.
update_one & upsert(bool v)
Set the "upsert" field.
update_one & sort(bsoncxx::v1::document::value v)
Set the "sort" field.
update_one & collation(bsoncxx::v1::document::value v)
Set the "collation" field.
bsoncxx::v1::document::view update() const
Return the current "update" field.
~update_one()
Destroy this object.
update_one & hint(v1::hint v)
Set the "hint" field.
bsoncxx::v1::document::view filter() const
Return the current "filter" field.
type
Enumeration identifying the type of a write operation.
Definition bulk_write.hpp:64
@ k_delete_one
A "Delete One" operation.
Definition bulk_write.hpp:73
@ k_insert_one
An "Insert One" operation.
Definition bulk_write.hpp:68
@ k_update_many
An "Update Many" operation.
Definition bulk_write.hpp:88
@ k_update_one
An "Update One" operation.
Definition bulk_write.hpp:83
@ k_delete_many
A "Delete Many" operation.
Definition bulk_write.hpp:78
@ k_replace_one
A "Replace One" operation.
Definition bulk_write.hpp:93
bulk_write & append(single const &op)
Append a single write operation.
~bulk_write()
Destroy this object.
bsoncxx::v1::stdx::optional< result > execute()
Execute the appended operations.
bulk_write(bulk_write &&other) noexcept
Move constructor.
bool empty() const
Return true when there are no appended operations.
A MongoDB aggregation pipeline.
Definition pipeline.hpp:43
Provides macros to control the set of symbols exported in the ABI.
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition export.hpp:52
The mongocxx v1 macro guard postlude header.
The mongocxx v1 macro guard prelude header.
The top-level namespace within which all bsoncxx library entities are declared.
Declares entities representing options to use with various commands.
Declares entities representing the result of various commands.
Declares entities whose ABI stability is guaranteed for documented symbols.
The top-level namespace within which all mongocxx library entities are declared.
Provides bsoncxx::v1::array::value.
Declares bsoncxx::v1::array::view.
Declares entities related to bulk write operations.
Provides bsoncxx::v1::document::value.
Declares bsoncxx::v1::document::view.
Declares mongocxx::v1::hint.
Provides mongocxx::v1::hint.
Provides mongocxx::v1::pipeline.
Provides std::optional-related polyfills for library API usage.
Declares bsoncxx::v1::types::value.
Provides non-owning, read-only entities representing a BSON type value.
Provides mongocxx::v1::write_concern.