find_one_and_delete.hpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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/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 find_and_modify delete operation
  27. ///
  28. class MONGOCXX_API find_one_and_delete {
  29. public:
  30. /// Sets the collation for this operation.
  31. ///
  32. /// @param collation
  33. /// The new collation.
  34. ///
  35. /// @return
  36. /// A reference to the object on which this member function is being called. This facilitates
  37. /// method chaining.
  38. ///
  39. /// @see https://docs.mongodb.com/master/reference/command/findAndModify/
  40. ///
  41. find_one_and_delete& collation(bsoncxx::document::view_or_value collation);
  42. ///
  43. /// Retrieves the current collation for this operation.
  44. ///
  45. /// @return
  46. /// The current collation.
  47. ///
  48. /// @see https://docs.mongodb.com/master/reference/command/findAndModify/
  49. ///
  50. const stdx::optional<bsoncxx::document::view_or_value>& collation() const;
  51. ///
  52. /// Sets the maximum amount of time for this operation to run (server-side) in milliseconds.
  53. ///
  54. /// @param max_time
  55. /// The max amount of running time (in milliseconds).
  56. ///
  57. /// @return
  58. /// A reference to the object on which this member function is being called. This facilitates
  59. /// method chaining.
  60. ///
  61. /// @see https://docs.mongodb.com/master/reference/command/findAndModify/
  62. ///
  63. find_one_and_delete& max_time(std::chrono::milliseconds max_time);
  64. ///
  65. /// The current max_time setting.
  66. ///
  67. /// @return the current max time (in milliseconds).
  68. ///
  69. /// @see https://docs.mongodb.com/master/reference/command/findAndModify/
  70. ///
  71. const stdx::optional<std::chrono::milliseconds>& max_time() const;
  72. ///
  73. /// Sets a projection that limits the fields to return.
  74. ///
  75. /// @param projection
  76. /// The projection document.
  77. ///
  78. /// @return
  79. /// A reference to the object on which this member function is being called. This facilitates
  80. /// method chaining.
  81. ///
  82. /// @see https://docs.mongodb.com/master/reference/command/findAndModify/
  83. ///
  84. find_one_and_delete& projection(bsoncxx::document::view_or_value projection);
  85. ///
  86. /// Gets the current projection set on this operation.
  87. ///
  88. /// @return The current projection.
  89. ///
  90. /// @see https://docs.mongodb.com/master/reference/command/findAndModify/
  91. ///
  92. const stdx::optional<bsoncxx::document::view_or_value>& projection() const;
  93. ///
  94. /// Sets the order to search for a matching document.
  95. ///
  96. /// @warning This can influence which document the operation modifies if the provided filter
  97. /// selects multiple documents.
  98. ///
  99. /// @param ordering
  100. /// Document describing the order of the documents to be returned.
  101. ///
  102. /// @return
  103. /// A reference to the object on which this member function is being called. This facilitates
  104. /// method chaining.
  105. ///
  106. /// @see https://docs.mongodb.com/master/reference/command/findAndModify/
  107. ///
  108. find_one_and_delete& sort(bsoncxx::document::view_or_value ordering);
  109. ///
  110. /// Gets the current sort ordering.
  111. ///
  112. /// @return The current sort ordering.
  113. ///
  114. /// @see https://docs.mongodb.com/master/reference/command/findAndModify/
  115. ///
  116. const stdx::optional<bsoncxx::document::view_or_value>& sort() const;
  117. ///
  118. /// Sets the write concern for this operation.
  119. ///
  120. /// @param write_concern
  121. /// Object representing the write concern.
  122. ///
  123. /// @return
  124. /// A reference to the object on which this member function is being called. This facilitates
  125. /// method chaining.
  126. ///
  127. /// @see
  128. /// https://docs.mongodb.com/master/reference/command/findAndModify/
  129. ///
  130. find_one_and_delete& write_concern(mongocxx::write_concern write_concern);
  131. ///
  132. /// Gets the current write concern.
  133. ///
  134. /// @return
  135. /// The current write concern.
  136. ///
  137. /// @see
  138. /// https://docs.mongodb.com/master/reference/command/findAndModify/
  139. ///
  140. const stdx::optional<mongocxx::write_concern>& write_concern() const;
  141. ///
  142. /// Sets the index to use for this operation.
  143. ///
  144. /// @note if the server already has a cached shape for this query, it may
  145. /// ignore a hint.
  146. ///
  147. /// @param index_hint
  148. /// Object representing the index to use.
  149. ///
  150. /// @return
  151. /// A reference to the object on which this member function is being called. This facilitates
  152. /// method chaining.
  153. ///
  154. find_one_and_delete& hint(class hint index_hint);
  155. ///
  156. /// Gets the current hint.
  157. ///
  158. /// @return The current hint, if one is set.
  159. ///
  160. const stdx::optional<class hint>& hint() const;
  161. private:
  162. stdx::optional<bsoncxx::document::view_or_value> _collation;
  163. stdx::optional<std::chrono::milliseconds> _max_time;
  164. stdx::optional<bsoncxx::document::view_or_value> _projection;
  165. stdx::optional<bsoncxx::document::view_or_value> _ordering;
  166. stdx::optional<mongocxx::write_concern> _write_concern;
  167. stdx::optional<class hint> _hint;
  168. };
  169. } // namespace options
  170. MONGOCXX_INLINE_NAMESPACE_END
  171. } // namespace mongocxx
  172. #include <mongocxx/config/postlude.hpp>