aggregate.hpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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/builder/basic/document.hpp>
  18. #include <bsoncxx/document/view_or_value.hpp>
  19. #include <bsoncxx/stdx/optional.hpp>
  20. #include <mongocxx/hint.hpp>
  21. #include <mongocxx/read_concern.hpp>
  22. #include <mongocxx/read_preference.hpp>
  23. #include <mongocxx/stdx.hpp>
  24. #include <mongocxx/write_concern.hpp>
  25. #include <mongocxx/config/prelude.hpp>
  26. namespace mongocxx {
  27. MONGOCXX_INLINE_NAMESPACE_BEGIN
  28. namespace options {
  29. ///
  30. /// Class representing the optional arguments to a MongoDB aggregation operation.
  31. ///
  32. class MONGOCXX_API aggregate {
  33. public:
  34. ///
  35. /// Enables writing to temporary files. When set to @c true, aggregation stages can write data
  36. /// to the _tmp subdirectory in the dbPath directory. The server-side default is @c false.
  37. ///
  38. /// @param allow_disk_use
  39. /// Whether or not to allow disk use.
  40. ///
  41. /// @return
  42. /// A reference to the object on which this member function is being called. This facilitates
  43. /// method chaining.
  44. ///
  45. /// @see https://docs.mongodb.com/master/reference/command/aggregate/
  46. ///
  47. aggregate& allow_disk_use(bool allow_disk_use);
  48. ///
  49. /// Retrieves the current allow_disk_use setting.
  50. ///
  51. /// @return Whether disk use is allowed.
  52. ///
  53. /// @see https://docs.mongodb.com/master/reference/command/aggregate/
  54. ///
  55. const stdx::optional<bool>& allow_disk_use() const;
  56. ///
  57. /// Sets the number of documents to return per batch.
  58. ///
  59. /// @param batch_size
  60. /// The size of the batches to request.
  61. ///
  62. /// @return
  63. /// A reference to the object on which this member function is being called. This facilitates
  64. /// method chaining.
  65. ///
  66. /// @see https://docs.mongodb.com/master/reference/command/aggregate/
  67. ///
  68. aggregate& batch_size(std::int32_t batch_size);
  69. ///
  70. /// The current batch size setting.
  71. ///
  72. /// @return The current batch size.
  73. ///
  74. /// @see https://docs.mongodb.com/master/reference/command/aggregate/
  75. ///
  76. const stdx::optional<std::int32_t>& batch_size() const;
  77. ///
  78. /// Sets the collation for this operation.
  79. ///
  80. /// @param collation
  81. /// The new collation.
  82. ///
  83. /// @return
  84. /// A reference to the object on which this member function is being called. This facilitates
  85. /// method chaining.
  86. ///
  87. /// @see https://docs.mongodb.com/master/reference/command/aggregate/
  88. ///
  89. aggregate& collation(bsoncxx::document::view_or_value collation);
  90. ///
  91. /// Retrieves the current collation for this operation.
  92. ///
  93. /// @return
  94. /// The current collation.
  95. ///
  96. /// @see https://docs.mongodb.com/master/reference/command/aggregate/
  97. ///
  98. const stdx::optional<bsoncxx::document::view_or_value>& collation() const;
  99. ///
  100. /// Sets the maximum amount of time for this operation to run server-side in milliseconds.
  101. ///
  102. /// @param max_time
  103. /// The max amount of time (in milliseconds).
  104. ///
  105. /// @return
  106. /// A reference to the object on which this member function is being called. This facilitates
  107. /// method chaining.
  108. ///
  109. /// @see https://docs.mongodb.com/master/reference/command/aggregate/
  110. ///
  111. aggregate& max_time(std::chrono::milliseconds max_time);
  112. ///
  113. /// The current max_time setting.
  114. ///
  115. /// @return
  116. /// The current max time (in milliseconds).
  117. ///
  118. /// @see https://docs.mongodb.com/master/reference/command/aggregate/
  119. ///
  120. const stdx::optional<std::chrono::milliseconds>& max_time() const;
  121. ///
  122. /// Sets the read_preference for this operation.
  123. ///
  124. /// @param rp the new read_preference
  125. ///
  126. /// @return
  127. /// A reference to the object on which this member function is being called. This facilitates
  128. /// method chaining.
  129. ///
  130. /// @see https://docs.mongodb.com/master/reference/command/aggregate/
  131. ///
  132. aggregate& read_preference(class read_preference rp);
  133. ///
  134. /// The current read_preference for this operation.
  135. ///
  136. /// @return the current read_preference
  137. ///
  138. /// @see https://docs.mongodb.com/master/reference/command/aggregate/
  139. ///
  140. const stdx::optional<class read_preference>& read_preference() const;
  141. ///
  142. /// Sets whether the $out stage should bypass document validation.
  143. ///
  144. /// @param bypass_document_validation whether or not to bypass validation.
  145. ///
  146. /// @return
  147. /// A reference to the object on which this member function is being called. This facilitates
  148. /// method chaining.
  149. ///
  150. aggregate& bypass_document_validation(bool bypass_document_validation);
  151. ///
  152. /// The current bypass_document_validation setting.
  153. ///
  154. /// @return the current bypass_document_validation setting
  155. ///
  156. /// @see https://docs.mongodb.com/master/reference/command/aggregate/
  157. ///
  158. const stdx::optional<bool>& bypass_document_validation() const;
  159. ///
  160. /// Sets the index to use for this operation.
  161. ///
  162. /// @see https://docs.mongodb.com/master/reference/command/aggregate/
  163. ///
  164. /// @note if the server already has a cached shape for this query, it may
  165. /// ignore a hint.
  166. ///
  167. /// @param index_hint
  168. /// Object representing the index to use.
  169. ///
  170. /// @return
  171. /// A reference to the object on which this member function is being called. This facilitates
  172. /// method chaining.
  173. ///
  174. aggregate& hint(class hint index_hint);
  175. ///
  176. /// Gets the current hint.
  177. ///
  178. /// @return The current hint, if one is set.
  179. ///
  180. /// @see https://docs.mongodb.com/master/reference/command/aggregate/
  181. ///
  182. const stdx::optional<class hint>& hint() const;
  183. ///
  184. /// Sets the write concern to use for this operation. Only has an effect if $out is a part of
  185. /// the pipeline.
  186. ///
  187. /// @see
  188. /// https://docs.mongodb.com/master/reference/command/aggregate/
  189. ///
  190. /// @param write_concern
  191. /// Object representing the write_concern.
  192. ///
  193. /// @return
  194. /// A reference to the object on which this member function is being called. This facilitates
  195. /// method chaining.
  196. ///
  197. aggregate& write_concern(class write_concern write_concern);
  198. ///
  199. /// Gets the current write concern.
  200. ///
  201. /// @return
  202. /// The current write concern, if it is set.
  203. ///
  204. /// @see
  205. /// https://docs.mongodb.com/master/reference/command/aggregate/
  206. ///
  207. const stdx::optional<class write_concern>& write_concern() const;
  208. ///
  209. /// Sets the read concern to use for this operation.
  210. ///
  211. /// @see
  212. /// https://docs.mongodb.com/master/reference/command/aggregate/
  213. ///
  214. /// @param read_concern
  215. /// Object representing the read_concern.
  216. ///
  217. /// @return
  218. /// A reference to the object on which this member function is being called.
  219. ///
  220. aggregate& read_concern(class read_concern read_concern);
  221. ///
  222. /// Gets the current read concern.
  223. ///
  224. /// @return
  225. /// The current read concern, if it is set.
  226. ///
  227. /// @see
  228. /// https://docs.mongodb.com/master/reference/command/aggregate/
  229. ///
  230. const stdx::optional<class read_concern>& read_concern() const;
  231. private:
  232. friend class ::mongocxx::database;
  233. friend class ::mongocxx::collection;
  234. void append(bsoncxx::builder::basic::document& builder) const;
  235. stdx::optional<bool> _allow_disk_use;
  236. stdx::optional<std::int32_t> _batch_size;
  237. stdx::optional<bsoncxx::document::view_or_value> _collation;
  238. stdx::optional<std::chrono::milliseconds> _max_time;
  239. stdx::optional<class read_preference> _read_preference;
  240. stdx::optional<bool> _bypass_document_validation;
  241. stdx::optional<class hint> _hint;
  242. stdx::optional<class write_concern> _write_concern;
  243. stdx::optional<class read_concern> _read_concern;
  244. };
  245. } // namespace options
  246. MONGOCXX_INLINE_NAMESPACE_END
  247. } // namespace mongocxx
  248. #include <mongocxx/config/postlude.hpp>