delete_one.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 <bsoncxx/document/view_or_value.hpp>
  16. #include <bsoncxx/stdx/optional.hpp>
  17. #include <mongocxx/hint.hpp>
  18. #include <mongocxx/stdx.hpp>
  19. #include <mongocxx/config/prelude.hpp>
  20. namespace mongocxx {
  21. MONGOCXX_INLINE_NAMESPACE_BEGIN
  22. namespace model {
  23. ///
  24. /// Class representing a MongoDB delete operation that removes a single document.
  25. ///
  26. class MONGOCXX_API delete_one {
  27. public:
  28. ///
  29. /// Constructs a delete operation that will delete the first document matching the filter.
  30. ///
  31. /// @param filter
  32. /// Document representing the criteria for deletion.
  33. ///
  34. delete_one(bsoncxx::document::view_or_value filter);
  35. ///
  36. /// Gets the filter on this delete operation.
  37. ///
  38. /// @return The filter to be used for the delete operation.
  39. ///
  40. const bsoncxx::document::view_or_value& filter() const;
  41. ///
  42. /// Sets the collation for this delete operation.
  43. ///
  44. /// @param collation
  45. /// The new collation.
  46. ///
  47. /// @see
  48. /// https://docs.mongodb.com/master/reference/collation/
  49. ///
  50. delete_one& collation(bsoncxx::document::view_or_value collation);
  51. ///
  52. /// Gets the collation option for this delete operation.
  53. ///
  54. /// @return
  55. /// The optional value of the collation option.
  56. ///
  57. /// @see
  58. /// https://docs.mongodb.com/master/reference/collation/
  59. ///
  60. const stdx::optional<bsoncxx::document::view_or_value>& collation() const;
  61. ///
  62. /// Sets the index to use for this operation.
  63. ///
  64. /// @note if the server already has a cached shape for this query, it may
  65. /// ignore a hint.
  66. ///
  67. /// @param index_hint
  68. /// Object representing the index to use.
  69. ///
  70. /// @return
  71. /// A reference to the object on which this member function is being called. This facilitates
  72. /// method chaining.
  73. ///
  74. delete_one& hint(class hint index_hint);
  75. ///
  76. /// Gets the current hint.
  77. ///
  78. /// @return The current hint, if one is set.
  79. ///
  80. const stdx::optional<class hint>& hint() const;
  81. private:
  82. bsoncxx::document::view_or_value _filter;
  83. stdx::optional<bsoncxx::document::view_or_value> _collation;
  84. stdx::optional<class hint> _hint;
  85. };
  86. } // namespace model
  87. MONGOCXX_INLINE_NAMESPACE_END
  88. } // namespace mongocxx
  89. #include <mongocxx/config/postlude.hpp>