update.hpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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/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 update operation.
  27. ///
  28. class MONGOCXX_API update {
  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. update& 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. update& 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 index to use for this operation.
  78. ///
  79. /// @note if the server already has a cached shape for this query, it may
  80. /// ignore a hint.
  81. ///
  82. /// @param index_hint
  83. /// Object representing the index to use.
  84. ///
  85. /// @return
  86. /// A reference to the object on which this member function is being called. This facilitates
  87. /// method chaining.
  88. ///
  89. update& hint(class hint index_hint);
  90. ///
  91. /// Gets the current hint.
  92. ///
  93. /// @return The current hint, if one is set.
  94. ///
  95. const stdx::optional<class hint>& hint() const;
  96. ///
  97. /// Sets the upsert option.
  98. ///
  99. /// By default, if no document matches the filter, the update operation does nothing.
  100. /// However, by specifying upsert as @c true, this operation either updates matching documents
  101. /// or inserts a new document using the update specification if no matching document exists.
  102. ///
  103. /// @param upsert
  104. /// If set to @c true, creates a new document when no document matches the query criteria.
  105. /// The server-side default is @c false, which does not insert a new document if a match
  106. /// is not found.
  107. ///
  108. /// @return
  109. /// A reference to the object on which this member function is being called. This facilitates
  110. /// method chaining.
  111. ///
  112. update& upsert(bool upsert);
  113. ///
  114. /// Gets the current value of the upsert option.
  115. ///
  116. /// @return The optional value of the upsert option.
  117. ///
  118. const stdx::optional<bool>& upsert() const;
  119. ///
  120. /// Sets the write_concern for this operation.
  121. ///
  122. /// @param wc
  123. /// The new write_concern
  124. ///
  125. /// @return
  126. /// A reference to the object on which this member function is being called. This facilitates
  127. /// method chaining.
  128. ///
  129. /// @see https://docs.mongodb.com/master/core/write-concern/
  130. ///
  131. update& write_concern(class write_concern wc);
  132. ///
  133. /// The current write_concern for this operation.
  134. ///
  135. /// @return
  136. /// The current write_concern
  137. ///
  138. /// @see https://docs.mongodb.com/master/core/write-concern/
  139. ///
  140. const stdx::optional<class write_concern>& write_concern() const;
  141. ///
  142. /// Set array filters for this operation.
  143. ///
  144. /// @param array_filters
  145. /// Array representing filters determining which array elements to modify.
  146. ///
  147. /// @return
  148. /// A reference to the object on which this member function is being called. This facilitates
  149. /// method chaining.
  150. ///
  151. /// @see https://docs.mongodb.com/manual/reference/command/update/
  152. ///
  153. update& array_filters(bsoncxx::array::view_or_value array_filters);
  154. ///
  155. /// Get array filters for this operation.
  156. ///
  157. /// @return
  158. /// The current array filters.
  159. ///
  160. /// @see https://docs.mongodb.com/manual/reference/command/update/
  161. ///
  162. const stdx::optional<bsoncxx::array::view_or_value>& array_filters() const;
  163. private:
  164. stdx::optional<bool> _bypass_document_validation;
  165. stdx::optional<bsoncxx::document::view_or_value> _collation;
  166. stdx::optional<bool> _upsert;
  167. stdx::optional<class write_concern> _write_concern;
  168. stdx::optional<bsoncxx::array::view_or_value> _array_filters;
  169. stdx::optional<class hint> _hint;
  170. };
  171. } // namespace options
  172. MONGOCXX_INLINE_NAMESPACE_END
  173. } // namespace mongocxx
  174. #include <mongocxx/config/postlude.hpp>