insert.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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/document/view.hpp>
  16. #include <bsoncxx/stdx/optional.hpp>
  17. #include <mongocxx/stdx.hpp>
  18. #include <mongocxx/write_concern.hpp>
  19. #include <mongocxx/config/prelude.hpp>
  20. namespace mongocxx {
  21. MONGOCXX_INLINE_NAMESPACE_BEGIN
  22. namespace options {
  23. ///
  24. /// Class representing the optional arguments to a MongoDB insert operation
  25. ///
  26. class MONGOCXX_API insert {
  27. public:
  28. ///
  29. /// Sets the bypass_document_validation option.
  30. /// If true, allows the write to opt-out of document level validation.
  31. ///
  32. /// @note
  33. /// On servers >= 3.2, the server applies validation by default. On servers < 3.2, this option
  34. /// is ignored.
  35. ///
  36. /// @param bypass_document_validation
  37. /// Whether or not to bypass document validation
  38. ///
  39. /// @return
  40. /// A reference to the object on which this member function is being called. This facilitates
  41. /// method chaining.
  42. ///
  43. insert& bypass_document_validation(bool bypass_document_validation);
  44. ///
  45. /// Gets the current value of the bypass_document_validation option.
  46. ///
  47. /// @return The optional value of the bypass_document_validation option.
  48. ///
  49. const stdx::optional<bool>& bypass_document_validation() const;
  50. ///
  51. /// Sets the write_concern for this operation.
  52. ///
  53. /// @param wc
  54. /// The new write_concern.
  55. ///
  56. /// @see https://docs.mongodb.com/master/core/write-concern/
  57. ///
  58. /// @return
  59. /// A reference to the object on which this member function is being called. This facilitates
  60. /// method chaining.
  61. ///
  62. insert& write_concern(class write_concern wc);
  63. ///
  64. /// The current write_concern for this operation.
  65. ///
  66. /// @return The current write_concern.
  67. ///
  68. /// @see https://docs.mongodb.com/master/core/write-concern/
  69. ///
  70. const stdx::optional<class write_concern>& write_concern() const;
  71. ///
  72. /// @note: This applies only to insert_many and is ignored for insert_one.
  73. ///
  74. /// If true, when an insert fails, return without performing the remaining
  75. /// writes. If false, when a write fails, continue with the remaining
  76. /// writes, if any. Inserts can be performed in any order if this is false.
  77. /// Defaults to true.
  78. ///
  79. /// @param ordered
  80. /// Whether or not the insert_many will be ordered.
  81. ///
  82. /// @return
  83. /// A reference to the object on which this member function is being called. This facilitates
  84. /// method chaining.
  85. ///
  86. /// @see https://docs.mongodb.com/master/reference/command/insert/
  87. ///
  88. insert& ordered(bool ordered);
  89. ///
  90. /// The current ordered value for this operation.
  91. ///
  92. /// @return The current ordered value.
  93. ///
  94. /// @see https://docs.mongodb.com/master/reference/command/insert/
  95. ///
  96. const stdx::optional<bool>& ordered() const;
  97. private:
  98. stdx::optional<class write_concern> _write_concern;
  99. stdx::optional<bool> _ordered;
  100. stdx::optional<bool> _bypass_document_validation;
  101. };
  102. } // namespace options
  103. MONGOCXX_INLINE_NAMESPACE_END
  104. } // namespace mongocxx
  105. #include <mongocxx/config/postlude.hpp>