bucket.hpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // Copyright 2017 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 <string>
  16. #include <bsoncxx/stdx/optional.hpp>
  17. #include <mongocxx/read_concern.hpp>
  18. #include <mongocxx/read_preference.hpp>
  19. #include <mongocxx/stdx.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. namespace gridfs {
  26. ///
  27. /// Class representing the optional arguments to a MongoDB GridFS bucket creation operation.
  28. ///
  29. class MONGOCXX_API bucket {
  30. public:
  31. ///
  32. /// Sets the name of the bucket. Defaults to 'fs'.
  33. ///
  34. /// @param bucket_name
  35. /// The name of the bucket.
  36. ///
  37. /// @return
  38. /// A reference to the object on which this member function is being called. This facilitates
  39. /// method chaining.
  40. ///
  41. bucket& bucket_name(std::string bucket_name);
  42. ///
  43. /// Gets the name of the bucket.
  44. ///
  45. /// @return
  46. /// The name of the bucket.
  47. ///
  48. const stdx::optional<std::string>& bucket_name() const;
  49. ///
  50. /// Sets the size of the chunks in the bucket. This will be used as the chunk size for files
  51. /// uploaded through the bucket without a custom size specified. Defaults to 255KB (255 * 1024).
  52. ///
  53. /// @param chunk_size_bytes
  54. /// The size of the chunks in bytes.
  55. ///
  56. /// @return
  57. /// A reference to the object on which this member function is being called. This facilitates
  58. /// method chaining.
  59. ///
  60. bucket& chunk_size_bytes(std::int32_t chunk_size_bytes);
  61. ///
  62. /// Gets the size of the chunks in the bucket.
  63. ///
  64. /// @return
  65. /// The size of the chunks in the bucket in bytes.
  66. ///
  67. const stdx::optional<std::int32_t>& chunk_size_bytes() const;
  68. ///
  69. /// Sets the read concern to be used when reading from the bucket. Defaults to the read
  70. /// concern of the database containing the bucket's collections.
  71. ///
  72. /// @param read_concern
  73. /// The read concern of the bucket.
  74. ///
  75. /// @return
  76. /// A reference to the object on which this member function is being called. This facilitates
  77. /// method chaining.
  78. ///
  79. bucket& read_concern(class read_concern read_concern);
  80. ///
  81. /// Gets the read concern of the bucket.
  82. ///
  83. /// @return
  84. /// The read concern of the bucket.
  85. ///
  86. const stdx::optional<class read_concern>& read_concern() const;
  87. ///
  88. /// Sets the read preference to be used when reading from the GridFS bucket. Defaults to the
  89. /// read preference of the database containing the bucket's collections.
  90. ///
  91. /// @note
  92. /// Because many GridFS operations require multiple independent reads from separate
  93. /// collections, use with secondaries is strongly discouraged because reads could go to
  94. /// different secondaries, resulting in inconsistent data if all file and chunk documents have
  95. /// not replicated to all secondaries.
  96. ///
  97. /// @param read_preference
  98. /// The read preference of the GridFS bucket.
  99. ///
  100. /// @return
  101. /// A reference to the object on which this member function is being called. This facilitates
  102. /// method chaining.
  103. ///
  104. bucket& read_preference(class read_preference read_preference);
  105. ///
  106. /// Gets the read preference of the bucket.
  107. ///
  108. /// @return
  109. /// The read preference of the bucket.
  110. ///
  111. const stdx::optional<class read_preference>& read_preference() const;
  112. ///
  113. /// Sets the write concern to be used when writing to the GridFS bucket. Defaults to the write
  114. /// concern of the database containing the bucket's collections.
  115. ///
  116. /// @param write_concern
  117. /// The write concern of the GridFS bucket.
  118. ///
  119. /// @return
  120. /// A reference to the object on which this member function is being called. This facilitates
  121. /// method chaining.
  122. ///
  123. bucket& write_concern(class write_concern write_concern);
  124. ///
  125. /// Gets the write concern of the bucket.
  126. ///
  127. /// @return
  128. /// The write concern of the bucket.
  129. ///
  130. const stdx::optional<class write_concern>& write_concern() const;
  131. private:
  132. stdx::optional<std::string> _bucket_name;
  133. stdx::optional<std::int32_t> _chunk_size_bytes;
  134. stdx::optional<class read_concern> _read_concern;
  135. stdx::optional<class read_preference> _read_preference;
  136. stdx::optional<class write_concern> _write_concern;
  137. };
  138. } // namespace gridfs
  139. } // namespace options
  140. MONGOCXX_INLINE_NAMESPACE_END
  141. } // namespace mongocxx
  142. #include <mongocxx/config/postlude.hpp>