create_collection.hpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. // Copyright 2015 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 <bsoncxx/document/view_or_value.hpp>
  16. #include <bsoncxx/stdx/optional.hpp>
  17. #include <mongocxx/stdx.hpp>
  18. #include <mongocxx/validation_criteria.hpp>
  19. #include <mongocxx/config/prelude.hpp>
  20. namespace mongocxx {
  21. MONGOCXX_INLINE_NAMESPACE_BEGIN
  22. namespace options {
  23. ///
  24. /// Class representing the optional arguments to a MongoDB createCollection command
  25. ///
  26. /// This class is deprecated, as are the database class methods that use this class.
  27. /// Please use the new database::create_collection methods that take options as a
  28. /// BSON document.
  29. ///
  30. class MONGOCXX_API create_collection_deprecated {
  31. public:
  32. ///
  33. /// To create a capped collection, specify true.
  34. ///
  35. /// @note If you specify true, you must also set a maximum size using the size() method.
  36. ///
  37. /// @param capped
  38. /// Whether or not this collection will be capped.
  39. ///
  40. /// @return
  41. /// A reference to the object on which this member function is being called. This facilitates
  42. /// method chaining.
  43. ///
  44. /// @see https://docs.mongodb.com/master/reference/glossary/#term-capped-collection
  45. ///
  46. create_collection_deprecated& capped(bool capped);
  47. ///
  48. /// Gets the current capped setting.
  49. ///
  50. /// @return
  51. /// Whether or not this collection will be capped.
  52. ///
  53. /// @see https://docs.mongodb.com/master/reference/glossary/#term-capped-collection
  54. ///
  55. const stdx::optional<bool>& capped() const;
  56. ///
  57. /// Sets the default collation for this collection.
  58. ///
  59. /// @param collation
  60. /// The default collation for the collection.
  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
  67. /// https://docs.mongodb.com/master/reference/collation/
  68. ///
  69. create_collection_deprecated& collation(bsoncxx::document::view_or_value collation);
  70. ///
  71. /// Gets the default collation for this collection.
  72. ///
  73. /// @return
  74. /// The default collation for the collection.
  75. ///
  76. /// @see
  77. /// https://docs.mongodb.com/master/reference/collation/
  78. ///
  79. const stdx::optional<bsoncxx::document::view_or_value>& collation() const;
  80. ///
  81. /// The maximum number of documents allowed in the capped collection.
  82. ///
  83. /// @note The size limit takes precedence over this limit. If a capped collection reaches
  84. /// the size limit before it reaches the maximum number of documents, MongoDB removes
  85. /// old documents.
  86. ///
  87. /// @param max_documents
  88. /// Maximum number of documents allowed in the collection (if capped).
  89. ///
  90. /// @return
  91. /// A reference to the object on which this member function is being called. This facilitates
  92. /// method chaining.
  93. ///
  94. create_collection_deprecated& (max)(std::int64_t max_documents);
  95. ///
  96. /// Gets the current setting for the maximum number of documents allowed in the capped
  97. /// collection.
  98. ///
  99. /// @return
  100. /// Maximum number of documents allowed in the collection (if capped).
  101. ///
  102. const stdx::optional<std::int64_t>& (max)() const;
  103. ///
  104. /// When true, disables the power of 2 sizes allocation for the collection.
  105. ///
  106. /// @see https://docs.mongodb.com/master/reference/command/create/
  107. ///
  108. /// @param no_padding
  109. /// When true, disables power of 2 sizing for this collection.
  110. ///
  111. /// @return
  112. /// A reference to the object on which this member function is being called. This facilitates
  113. /// method chaining.
  114. ///
  115. create_collection_deprecated& no_padding(bool no_padding);
  116. ///
  117. /// Gets the current value of the "no padding" option for the collection.
  118. ///
  119. /// @see https://docs.mongodb.com/master/reference/command/create/
  120. ///
  121. /// @return
  122. /// When true, power of 2 sizing is disabled for this collection.
  123. ///
  124. const stdx::optional<bool>& no_padding() const;
  125. ///
  126. /// A maximum size, in bytes, for a capped collection.
  127. ///
  128. /// @note Once a capped collection reaches its maximum size, MongoDB removes older
  129. /// documents to make space for new documents.
  130. ///
  131. /// @note Size is required for capped collections and ignored for other collections.
  132. ///
  133. /// @param max_size
  134. /// Maximum size, in bytes, of this collection (if capped).
  135. ///
  136. /// @return
  137. /// A reference to the object on which this member function is being called. This facilitates
  138. /// method chaining.
  139. ///
  140. create_collection_deprecated& size(std::int64_t max_size);
  141. ///
  142. /// Gets the current size setting, for a capped collection.
  143. ///
  144. /// @return
  145. /// Maximum size, in bytes, of this collection (if capped).
  146. ///
  147. const stdx::optional<std::int64_t>& size() const;
  148. ///
  149. /// Specify configuration to the storage on a per-collection basis.
  150. ///
  151. /// @note This option is currently only available with the WiredTiger storage engine.
  152. ///
  153. /// @param storage_engine_opts
  154. /// Configuration options specific to the storage engine.
  155. ///
  156. /// @return
  157. /// A reference to the object on which this member function is being called. This facilitates
  158. /// method chaining.
  159. ///
  160. create_collection_deprecated& storage_engine(
  161. bsoncxx::document::view_or_value storage_engine_opts);
  162. ///
  163. /// Gets the current storage engine configuration for this collection.
  164. ///
  165. /// @return
  166. /// Configuration options specific to the storage engine.
  167. ///
  168. const stdx::optional<bsoncxx::document::view_or_value>& storage_engine() const;
  169. ///
  170. /// Specify validation criteria for this collection.
  171. ///
  172. /// @param validation
  173. /// Validation criteria for this collection.
  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/core/document-validation/
  180. ///
  181. create_collection_deprecated& validation_criteria(class validation_criteria validation);
  182. ///
  183. /// Gets the current validation criteria for this collection.
  184. ///
  185. /// @return
  186. /// Validation criteria for this collection.
  187. ///
  188. /// @see https://docs.mongodb.com/master/core/document-validation/
  189. ///
  190. const stdx::optional<class validation_criteria>& validation_criteria() const;
  191. ///
  192. /// Return a bson document representing the options set on this object.
  193. ///
  194. /// @deprecated
  195. /// This method is deprecated. To determine which options are set on this object, use the
  196. /// provided accessors instead.
  197. ///
  198. /// @return Options, as a document.
  199. ///
  200. MONGOCXX_DEPRECATED bsoncxx::document::value to_document() const;
  201. bsoncxx::document::value to_document_deprecated() const;
  202. ///
  203. /// @deprecated
  204. /// This method is deprecated. To determine which options are set on this object, use the
  205. /// provided accessors instead.
  206. ///
  207. MONGOCXX_DEPRECATED MONGOCXX_INLINE operator bsoncxx::document::value() const;
  208. private:
  209. stdx::optional<bool> _capped;
  210. stdx::optional<bsoncxx::document::view_or_value> _collation;
  211. stdx::optional<std::int64_t> _max_documents;
  212. stdx::optional<std::int64_t> _max_size;
  213. stdx::optional<bool> _no_padding;
  214. stdx::optional<bsoncxx::document::view_or_value> _storage_engine_opts;
  215. stdx::optional<class validation_criteria> _validation;
  216. };
  217. MONGOCXX_DEPRECATED typedef create_collection_deprecated create_collection;
  218. MONGOCXX_INLINE create_collection_deprecated::operator bsoncxx::document::value() const {
  219. return to_document_deprecated();
  220. }
  221. } // namespace options
  222. MONGOCXX_INLINE_NAMESPACE_END
  223. } // namespace mongocxx
  224. #include <mongocxx/config/postlude.hpp>