find_one_and_update.hpp 10.0 KB

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