count.hpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 <string>
  18. #include <bsoncxx/document/view_or_value.hpp>
  19. #include <bsoncxx/stdx/optional.hpp>
  20. #include <mongocxx/hint.hpp>
  21. #include <mongocxx/read_preference.hpp>
  22. #include <mongocxx/config/prelude.hpp>
  23. namespace mongocxx {
  24. MONGOCXX_INLINE_NAMESPACE_BEGIN
  25. namespace options {
  26. ///
  27. /// Class representing the optional arguments to mongocxx::collection::count_documents
  28. ///
  29. class MONGOCXX_API count {
  30. public:
  31. ///
  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/aggregate/
  42. ///
  43. count& 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/aggregate/
  51. ///
  52. const stdx::optional<bsoncxx::document::view_or_value>& collation() const;
  53. ///
  54. /// Sets the index to use for this operation.
  55. ///
  56. /// @param index_hint
  57. /// Object representing the index to use.
  58. ///
  59. /// @return
  60. /// A reference to the object on which this member function is being called. This facilitates
  61. /// method chaining.
  62. ///
  63. /// @see https://docs.mongodb.com/master/reference/command/aggregate/
  64. ///
  65. count& hint(class hint index_hint);
  66. ///
  67. /// Gets the current hint.
  68. ///
  69. /// @return The current hint, if one is set.
  70. ///
  71. /// @see https://docs.mongodb.com/master/reference/command/aggregate/
  72. ///
  73. const stdx::optional<class hint>& hint() const;
  74. ///
  75. /// Sets the maximum number of documents to count.
  76. ///
  77. /// @param limit
  78. /// The max number of documents to count.
  79. ///
  80. /// @return
  81. /// A reference to the object on which this member function is being called. This facilitates
  82. /// method chaining.
  83. ///
  84. /// @see https://docs.mongodb.com/master/reference/command/aggregate/
  85. ///
  86. count& limit(std::int64_t limit);
  87. ///
  88. /// Gets the current limit.
  89. ///
  90. /// @return The current limit.
  91. ///
  92. /// @see https://docs.mongodb.com/master/reference/command/aggregate/
  93. ///
  94. const stdx::optional<std::int64_t>& limit() const;
  95. ///
  96. /// Sets the maximum amount of time for this operation to run (server-side) in milliseconds.
  97. ///
  98. /// @param max_time
  99. /// The max amount of time (in milliseconds).
  100. ///
  101. /// @return
  102. /// A reference to the object on which this member function is being called. This facilitates
  103. /// method chaining.
  104. ///
  105. /// @see https://docs.mongodb.com/master/reference/command/aggregate/
  106. ///
  107. count& max_time(std::chrono::milliseconds max_time);
  108. ///
  109. /// The current max_time setting.
  110. ///
  111. /// @return The current max time (in milliseconds).
  112. ///
  113. /// @see https://docs.mongodb.com/master/reference/command/aggregate/
  114. ///
  115. const stdx::optional<std::chrono::milliseconds>& max_time() const;
  116. ///
  117. /// Sets the number of documents to skip before counting documents.
  118. ///
  119. /// @param skip
  120. /// The number of documents to skip.
  121. ///
  122. /// @return
  123. /// A reference to the object on which this member function is being called. This facilitates
  124. /// method chaining.
  125. ///
  126. /// @see https://docs.mongodb.com/master/reference/command/aggregate/
  127. ///
  128. count& skip(std::int64_t skip);
  129. ///
  130. /// Gets the current number of documents to skip.
  131. ///
  132. /// @return The number of documents to skip.
  133. ///
  134. /// @see https://docs.mongodb.com/master/reference/command/aggregate/
  135. ///
  136. const stdx::optional<std::int64_t>& skip() const;
  137. ///
  138. /// Sets the read_preference for this operation.
  139. ///
  140. /// @param rp
  141. /// The new read_preference.
  142. ///
  143. /// @return
  144. /// A reference to the object on which this member function is being called. This facilitates
  145. /// method chaining.
  146. ///
  147. /// @see https://docs.mongodb.com/master/reference/command/aggregate/
  148. ///
  149. count& read_preference(class read_preference rp);
  150. ///
  151. /// The current read_preference for this operation.
  152. ///
  153. /// @return the current read_preference
  154. ///
  155. /// @see https://docs.mongodb.com/master/reference/command/aggregate/
  156. ///
  157. const stdx::optional<class read_preference>& read_preference() const;
  158. private:
  159. stdx::optional<bsoncxx::document::view_or_value> _collation;
  160. stdx::optional<class hint> _hint;
  161. stdx::optional<std::int64_t> _limit;
  162. stdx::optional<std::chrono::milliseconds> _max_time;
  163. stdx::optional<std::int64_t> _skip;
  164. stdx::optional<class read_preference> _read_preference;
  165. };
  166. } // namespace options
  167. MONGOCXX_INLINE_NAMESPACE_END
  168. } // namespace mongocxx
  169. #include <mongocxx/config/postlude.hpp>