replace.hpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // Copyright 2018-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. #pragma once
  15. #include <bsoncxx/array/view_or_value.hpp>
  16. #include <bsoncxx/document/view_or_value.hpp>
  17. #include <bsoncxx/stdx/optional.hpp>
  18. #include <mongocxx/hint.hpp>
  19. #include <mongocxx/stdx.hpp>
  20. #include <mongocxx/write_concern.hpp>
  21. #include <mongocxx/config/prelude.hpp>
  22. namespace mongocxx {
  23. MONGOCXX_INLINE_NAMESPACE_BEGIN
  24. namespace options {
  25. ///
  26. /// Class representing the optional arguments to a MongoDB replace operation.
  27. ///
  28. class MONGOCXX_API replace {
  29. public:
  30. ///
  31. /// Sets the bypass_document_validation option.
  32. /// If true, allows the write to opt-out of document level validation.
  33. ///
  34. /// @note
  35. /// On servers >= 3.2, the server applies validation by default. On servers < 3.2, this option
  36. /// is ignored.
  37. ///
  38. /// @param bypass_document_validation
  39. /// Whether or not to bypass document validation
  40. ///
  41. /// @return
  42. /// A reference to the object on which this member function is being called. This facilitates
  43. /// method chaining.
  44. ///
  45. replace& bypass_document_validation(bool bypass_document_validation);
  46. ///
  47. /// Gets the current value of the bypass_document_validation option.
  48. ///
  49. /// @return The optional value of the bypass_document_validation option.
  50. ///
  51. const stdx::optional<bool>& bypass_document_validation() const;
  52. ///
  53. /// Sets the collation for this operation.
  54. ///
  55. /// @param collation
  56. /// The new collation.
  57. ///
  58. /// @return
  59. /// A reference to the object on which this member function is being called. This facilitates
  60. /// method chaining.
  61. ///
  62. /// @see
  63. /// https://docs.mongodb.com/master/reference/collation/
  64. ///
  65. replace& collation(bsoncxx::document::view_or_value collation);
  66. ///
  67. /// Retrieves the current collation for this operation.
  68. ///
  69. /// @return
  70. /// The current collation.
  71. ///
  72. /// @see
  73. /// https://docs.mongodb.com/master/reference/collation/
  74. ///
  75. const stdx::optional<bsoncxx::document::view_or_value>& collation() const;
  76. ///
  77. /// Sets the upsert option.
  78. ///
  79. /// By default, if no document matches the filter, the replace operation does nothing.
  80. /// However, by specifying upsert as @c true, this operation either updates matching documents
  81. /// or inserts a new document using the replace specification if no matching document exists.
  82. ///
  83. /// @param upsert
  84. /// If set to @c true, creates a new document when no document matches the query criteria.
  85. /// The server-side default is @c false, which does not insert a new document if a match
  86. /// is not found.
  87. ///
  88. /// @return
  89. /// A reference to the object on which this member function is being called. This facilitates
  90. /// method chaining.
  91. ///
  92. replace& upsert(bool upsert);
  93. ///
  94. /// Gets the current value of the upsert option.
  95. ///
  96. /// @return The optional value of the upsert option.
  97. ///
  98. const stdx::optional<bool>& upsert() const;
  99. ///
  100. /// Sets the write_concern for this operation.
  101. ///
  102. /// @param wc
  103. /// The new write_concern
  104. ///
  105. /// @return
  106. /// A reference to the object on which this member function is being called. This facilitates
  107. /// method chaining.
  108. ///
  109. /// @see https://docs.mongodb.com/master/core/write-concern/
  110. ///
  111. replace& write_concern(class write_concern wc);
  112. ///
  113. /// The current write_concern for this operation.
  114. ///
  115. /// @return
  116. /// The current write_concern
  117. ///
  118. /// @see https://docs.mongodb.com/master/core/write-concern/
  119. ///
  120. const stdx::optional<class write_concern>& write_concern() const;
  121. ///
  122. /// Sets the index to use for this operation.
  123. ///
  124. /// @note if the server already has a cached shape for this query, it may
  125. /// ignore a hint.
  126. ///
  127. /// @param index_hint
  128. /// Object representing the index to use.
  129. ///
  130. /// @return
  131. /// A reference to the object on which this member function is being called. This facilitates
  132. /// method chaining.
  133. ///
  134. replace& hint(class hint index_hint);
  135. ///
  136. /// Gets the current hint.
  137. ///
  138. /// @return The current hint, if one is set.
  139. ///
  140. const stdx::optional<class hint>& hint() const;
  141. private:
  142. stdx::optional<bool> _bypass_document_validation;
  143. stdx::optional<bsoncxx::document::view_or_value> _collation;
  144. stdx::optional<bool> _upsert;
  145. stdx::optional<class write_concern> _write_concern;
  146. stdx::optional<class hint> _hint;
  147. };
  148. } // namespace options
  149. MONGOCXX_INLINE_NAMESPACE_END
  150. } // namespace mongocxx
  151. #include <mongocxx/config/postlude.hpp>