bulk_write.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #pragma once
  15. #include <bsoncxx/stdx/optional.hpp>
  16. #include <mongocxx/write_concern.hpp>
  17. #include <mongocxx/config/prelude.hpp>
  18. namespace mongocxx {
  19. MONGOCXX_INLINE_NAMESPACE_BEGIN
  20. namespace options {
  21. ///
  22. /// Class representing the optional arguments to a MongoDB bulk write
  23. ///
  24. class MONGOCXX_API bulk_write {
  25. public:
  26. ///
  27. /// Constructs a new bulk_write object. By default, bulk writes are considered ordered
  28. /// as this is the only safe choice. If you want an unordered update, you must call
  29. /// ordered(false) to switch to unordered mode.
  30. ///
  31. bulk_write();
  32. ///
  33. /// Sets whether the writes must be executed in order by the server.
  34. ///
  35. /// The server-side default is @c true.
  36. ///
  37. /// @param ordered
  38. /// If @c true all write operations will be executed serially in the order they were appended,
  39. /// and the entire bulk operation will abort on the first error. If @c false operations will
  40. /// be executed in arbitrary order (possibly in parallel on the server) and any errors will be
  41. /// reported after attempting all operations.
  42. ///
  43. /// @return
  44. /// A reference to the object on which this member function is being called. This facilitates
  45. /// method chaining.
  46. ///
  47. bulk_write& ordered(bool ordered);
  48. ///
  49. /// Gets the current value of the ordered option.
  50. ///
  51. /// @return The value of the ordered option.
  52. ///
  53. bool ordered() const;
  54. ///
  55. /// Sets the write_concern for this operation.
  56. ///
  57. /// @param wc
  58. /// The new write_concern.
  59. ///
  60. /// @return
  61. /// A reference to the object on which this member function is being called. This facilitates
  62. /// method chaining.
  63. ///
  64. /// @see https://docs.mongodb.com/master/core/write-concern/
  65. ///
  66. bulk_write& write_concern(class write_concern wc);
  67. ///
  68. /// The current write_concern for this operation.
  69. ///
  70. /// @return
  71. /// The current write_concern.
  72. ///
  73. /// @see https://docs.mongodb.com/master/core/write-concern/
  74. ///
  75. const stdx::optional<class write_concern>& write_concern() const;
  76. ///
  77. /// Set whether or not to bypass document validation for this operation.
  78. ///
  79. /// @param bypass_document_validation
  80. /// Whether or not to bypass document validation.
  81. ///
  82. /// @return
  83. /// A reference to the object on which this member function is being called. This facilitates
  84. /// method chaining.
  85. ///
  86. bulk_write& bypass_document_validation(bool bypass_document_validation);
  87. ///
  88. /// The current setting for bypassing document validation for this operation.
  89. ///
  90. /// @return
  91. /// The current document validation bypass setting.
  92. ///
  93. const stdx::optional<bool> bypass_document_validation() const;
  94. private:
  95. bool _ordered;
  96. stdx::optional<class write_concern> _write_concern;
  97. stdx::optional<bool> _bypass_document_validation;
  98. };
  99. } // namespace options
  100. MONGOCXX_INLINE_NAMESPACE_END
  101. } // namespace mongocxx
  102. #include <mongocxx/config/postlude.hpp>