index_view.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 <chrono>
  16. #include <bsoncxx/stdx/optional.hpp>
  17. #include <mongocxx/write_concern.hpp>
  18. #include <mongocxx/config/prelude.hpp>
  19. namespace mongocxx {
  20. MONGOCXX_INLINE_NAMESPACE_BEGIN
  21. namespace options {
  22. ///
  23. /// Class representing optional arguments to IndexView operations
  24. ///
  25. class MONGOCXX_API index_view {
  26. public:
  27. index_view();
  28. ///
  29. /// Sets the maximum amount of time for this operation to run (server-side) in milliseconds.
  30. ///
  31. /// @param max_time
  32. /// The max amount of time (in milliseconds).
  33. ///
  34. /// @return
  35. /// A reference to the object on which this member function is being called. This facilitates
  36. /// method chaining.
  37. ///
  38. /// @see
  39. /// https://docs.mongodb.com/master/reference/command/findAndModify/
  40. ///
  41. index_view& max_time(std::chrono::milliseconds max_time);
  42. ///
  43. /// The current max_time setting.
  44. ///
  45. /// @return
  46. /// The current max allowed running time (in milliseconds).
  47. ///
  48. /// @see
  49. /// https://docs.mongodb.com/master/reference/command/findAndModify/
  50. ///
  51. const bsoncxx::stdx::optional<std::chrono::milliseconds>& max_time() const;
  52. ///
  53. /// Sets the write concern for this operation.
  54. ///
  55. /// @param write_concern
  56. /// Object representing the write concern.
  57. ///
  58. /// @return
  59. /// A reference to the object on which this member function is being called. This facilitates
  60. /// method chaining.
  61. ///
  62. /// @see
  63. /// https://docs.mongodb.com/master/reference/command/findAndModify/
  64. ///
  65. index_view& write_concern(mongocxx::write_concern write_concern);
  66. ///
  67. /// Gets the current write concern.
  68. ///
  69. /// @return
  70. /// The current write concern.
  71. ///
  72. /// @see
  73. /// https://docs.mongodb.com/master/reference/command/findAndModify/
  74. ///
  75. const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern() const;
  76. ///
  77. /// Sets the commit quorum for this operation.
  78. ///
  79. /// This option may only be used with MongoDB version 4.4 or later.
  80. ///
  81. /// @param commit_quorum
  82. /// Integer representing the minimum number of data-bearing voting replica set members (i.e.
  83. /// commit quorum), including the primary, that must report a successful index build before
  84. /// the primary marks the indexes as ready. A value of @c 0 disables quorum-voting behavior.
  85. ///
  86. /// @return
  87. /// A reference to the object on which this member function is being called. This facilitates
  88. /// method chaining.
  89. ///
  90. /// @see
  91. /// https://docs.mongodb.com/master/reference/command/createIndexes
  92. ///
  93. index_view& commit_quorum(std::int32_t commit_quorum);
  94. ///
  95. /// Sets the commit quorum for this operation.
  96. ///
  97. /// This option may only be used with MongoDB version 4.4 or later.
  98. ///
  99. /// @param commit_quorum
  100. /// String representing the minimum number of data-bearing voting replica set members (i.e.
  101. /// commit quorum), including the primary, that must report a successful index build before
  102. /// the primary marks the indexes as ready.
  103. ///
  104. /// @return
  105. /// A reference to the object on which this member function is being called. This facilitates
  106. /// method chaining.
  107. ///
  108. /// @see
  109. /// https://docs.mongodb.com/master/reference/command/createIndexes
  110. ///
  111. index_view& commit_quorum(std::string commit_quorum);
  112. ///
  113. /// Gets the current commitQuorum setting.
  114. ///
  115. /// This option may only be used with MongoDB version 4.4 or later.
  116. ///
  117. /// @return
  118. /// The current commitQuorum setting.
  119. ///
  120. /// @see
  121. /// https://docs.mongodb.com/master/reference/command/createIndexes
  122. ///
  123. const stdx::optional<bsoncxx::document::value> commit_quorum() const;
  124. private:
  125. bsoncxx::stdx::optional<std::chrono::milliseconds> _max_time;
  126. bsoncxx::stdx::optional<mongocxx::write_concern> _write_concern;
  127. bsoncxx::stdx::optional<bsoncxx::document::value> _commit_quorum;
  128. };
  129. } // namespace options
  130. MONGOCXX_INLINE_NAMESPACE_END
  131. } // namespace mongocxx
  132. #include <mongocxx/config/postlude.hpp>