find_one_and_replace.hpp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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 <chrono>
  16. #include <cstdint>
  17. #include <bsoncxx/document/view_or_value.hpp>
  18. #include <bsoncxx/stdx/optional.hpp>
  19. #include <mongocxx/hint.hpp>
  20. #include <mongocxx/options/find_one_common_options.hpp>
  21. #include <mongocxx/stdx.hpp>
  22. #include <mongocxx/write_concern.hpp>
  23. #include <mongocxx/config/prelude.hpp>
  24. namespace mongocxx {
  25. MONGOCXX_INLINE_NAMESPACE_BEGIN
  26. namespace options {
  27. ///
  28. /// Class representing the optional arguments to a MongoDB find_and_modify replace operation
  29. ///
  30. class MONGOCXX_API find_one_and_replace {
  31. public:
  32. /// Sets the collation for this operation.
  33. ///
  34. /// @param collation
  35. /// The new collation.
  36. ///
  37. /// @return
  38. /// A reference to the object on which this member function is being called. This facilitates
  39. /// method chaining.
  40. ///
  41. /// @see https://docs.mongodb.com/master/reference/command/findAndModify/
  42. ///
  43. find_one_and_replace& collation(bsoncxx::document::view_or_value collation);
  44. ///
  45. /// Retrieves the current collation for this operation.
  46. ///
  47. /// @return
  48. /// The current collation.
  49. ///
  50. /// @see https://docs.mongodb.com/master/reference/command/findAndModify/
  51. ///
  52. const stdx::optional<bsoncxx::document::view_or_value>& collation() const;
  53. ///
  54. /// Whether or not to bypass document validation for this operation.
  55. ///
  56. /// @note
  57. /// On servers >= 3.2, the server applies validation by default. On servers < 3.2, this option
  58. /// is ignored.
  59. ///
  60. /// @param bypass_document_validation
  61. /// Whether or not to bypass document validation.
  62. ///
  63. /// @return
  64. /// A reference to the object on which this member function is being called. This facilitates
  65. /// method chaining.
  66. ///
  67. /// @see https://docs.mongodb.com/master/reference/command/findAndModify/
  68. ///
  69. find_one_and_replace& bypass_document_validation(bool bypass_document_validation);
  70. ///
  71. /// The current setting for bypassing document validation.
  72. ///
  73. /// @return the current bypass document validation setting.
  74. ///
  75. /// @see https://docs.mongodb.com/master/reference/command/findAndModify/
  76. ///
  77. const stdx::optional<bool>& bypass_document_validation() const;
  78. ///
  79. /// Sets the index to use for this operation.
  80. ///
  81. /// @note if the server already has a cached shape for this query, it may
  82. /// ignore a hint.
  83. ///
  84. /// @param index_hint
  85. /// Object representing the index to use.
  86. ///
  87. /// @return
  88. /// A reference to the object on which this member function is being called. This facilitates
  89. /// method chaining.
  90. ///
  91. find_one_and_replace& hint(class hint index_hint);
  92. ///
  93. /// Gets the current hint.
  94. ///
  95. /// @return The current hint, if one is set.
  96. ///
  97. const stdx::optional<class hint>& hint() const;
  98. ///
  99. /// Sets the maximum amount of time for this operation to run (server-side) in milliseconds.
  100. ///
  101. /// @param max_time
  102. /// The max amount of time (in milliseconds).
  103. ///
  104. /// @return
  105. /// A reference to the object on which this member function is being called. This facilitates
  106. /// method chaining.
  107. ///
  108. /// @see https://docs.mongodb.com/master/reference/command/findAndModify/
  109. ///
  110. find_one_and_replace& max_time(std::chrono::milliseconds max_time);
  111. ///
  112. /// The current max_time setting.
  113. ///
  114. /// @return the current max allowed running time (in milliseconds).
  115. ///
  116. /// @see https://docs.mongodb.com/master/reference/command/findAndModify/
  117. ///
  118. const stdx::optional<std::chrono::milliseconds>& max_time() const;
  119. ///
  120. /// Sets a projection, which limits the fields to return.
  121. ///
  122. /// @param projection
  123. /// The projection document.
  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/reference/command/findAndModify/
  130. ///
  131. find_one_and_replace& projection(bsoncxx::document::view_or_value projection);
  132. ///
  133. /// Gets the current projection for this operation.
  134. ///
  135. /// @return The current projection.
  136. ///
  137. /// @see https://docs.mongodb.com/master/reference/command/findAndModify/
  138. ///
  139. const stdx::optional<bsoncxx::document::view_or_value>& projection() const;
  140. ///
  141. /// Set the desired version of the replaced document to return, either the original
  142. /// document, or the replacement. By default, the original document is returned.
  143. ///
  144. /// @param return_document
  145. /// Version of document to return, either original or replaced.
  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/master/reference/command/findAndModify/
  152. /// @see mongocxx::options::return_document
  153. ///
  154. find_one_and_replace& return_document(return_document return_document);
  155. ///
  156. /// Which version of the replaced document to return.
  157. ///
  158. /// @return Version of document to return, either original or replacement.
  159. ///
  160. /// @see https://docs.mongodb.com/master/reference/command/findAndModify/
  161. /// @see mongocxx::options::return_document
  162. ///
  163. const stdx::optional<mongocxx::options::return_document>& return_document() const;
  164. ///
  165. /// Sets the order by which to search the collection for a matching document.
  166. ///
  167. /// @warning This can influence which document the operation modifies if the provided filter
  168. /// selects multiple documents.
  169. ///
  170. /// @param ordering
  171. /// Document describing the order of the documents to be returned.
  172. ///
  173. /// @return
  174. /// A reference to the object on which this member function is being called. This facilitates
  175. /// method chaining.
  176. ///
  177. /// @see https://docs.mongodb.com/master/reference/command/findAndModify/
  178. ///
  179. find_one_and_replace& sort(bsoncxx::document::view_or_value ordering);
  180. ///
  181. /// Gets the current sort ordering.
  182. ///
  183. /// @return The current sort ordering.
  184. ///
  185. /// @see https://docs.mongodb.com/master/reference/command/findAndModify/
  186. ///
  187. const stdx::optional<bsoncxx::document::view_or_value>& sort() const;
  188. ///
  189. /// Sets the upsert flag on the operation. When @c true, the operation creates a new document if
  190. /// no document matches the filter. When @c false, this operation will do nothing if there are
  191. /// no matching documents. The server-side default is false.
  192. ///
  193. /// @param upsert
  194. /// Whether or not to perform an upsert.
  195. ///
  196. /// @return
  197. /// A reference to the object on which this member function is being called. This facilitates
  198. /// method chaining.
  199. ///
  200. /// @see https://docs.mongodb.com/master/reference/command/findAndModify/
  201. ///
  202. find_one_and_replace& upsert(bool upsert);
  203. ///
  204. /// Gets the current upsert setting.
  205. ///
  206. /// @return The current upsert setting.
  207. ///
  208. /// @see https://docs.mongodb.com/master/reference/command/findAndModify/
  209. ///
  210. const stdx::optional<bool>& upsert() const;
  211. ///
  212. /// Sets the write concern for this operation.
  213. ///
  214. /// @param write_concern
  215. /// Object representing the write concern.
  216. ///
  217. /// @return
  218. /// A reference to the object on which this member function is being called. This facilitates
  219. /// method chaining.
  220. ///
  221. /// @see
  222. /// https://docs.mongodb.com/master/reference/command/findAndModify/
  223. ///
  224. find_one_and_replace& write_concern(mongocxx::write_concern write_concern);
  225. ///
  226. /// Gets the current write concern.
  227. ///
  228. /// @return
  229. /// The current write concern.
  230. ///
  231. /// @see
  232. /// https://docs.mongodb.com/master/reference/command/findAndModify/
  233. ///
  234. const stdx::optional<mongocxx::write_concern>& write_concern() const;
  235. private:
  236. stdx::optional<bool> _bypass_document_validation;
  237. stdx::optional<bsoncxx::document::view_or_value> _collation;
  238. stdx::optional<class hint> _hint;
  239. stdx::optional<std::chrono::milliseconds> _max_time;
  240. stdx::optional<bsoncxx::document::view_or_value> _projection;
  241. stdx::optional<mongocxx::options::return_document> _return_document;
  242. stdx::optional<bsoncxx::document::view_or_value> _ordering;
  243. stdx::optional<bool> _upsert;
  244. stdx::optional<mongocxx::write_concern> _write_concern;
  245. };
  246. } // namespace options
  247. MONGOCXX_INLINE_NAMESPACE_END
  248. } // namespace mongocxx
  249. #include <mongocxx/config/postlude.hpp>