update.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 <cstdint>
  16. #include <bsoncxx/stdx/optional.hpp>
  17. #include <bsoncxx/types.hpp>
  18. #include <mongocxx/result/bulk_write.hpp>
  19. #include <mongocxx/stdx.hpp>
  20. #include <mongocxx/config/prelude.hpp>
  21. namespace mongocxx {
  22. MONGOCXX_INLINE_NAMESPACE_BEGIN
  23. namespace result {
  24. /// Class representing the result of a MongoDB update operation.
  25. class MONGOCXX_API update {
  26. public:
  27. // This constructor is public for testing purposes only
  28. explicit update(result::bulk_write result);
  29. ///
  30. /// Returns the bulk write result for this update operation.
  31. ///
  32. /// @return The raw bulk write result.
  33. ///
  34. const result::bulk_write& result() const;
  35. ///
  36. /// Gets the number of documents that were matched during this operation.
  37. ///
  38. /// @return The number of documents that were matched.
  39. ///
  40. std::int32_t matched_count() const;
  41. ///
  42. /// Gets the number of documents that were modified during this operation.
  43. ///
  44. /// @return The number of documents that were modified.
  45. std::int32_t modified_count() const;
  46. ///
  47. /// If a document was upserted during this operation, gets the _id of the upserted document.
  48. ///
  49. /// @return The value of the _id field for upserted document.
  50. ///
  51. stdx::optional<bsoncxx::document::element> upserted_id() const;
  52. private:
  53. result::bulk_write _result;
  54. friend MONGOCXX_API bool MONGOCXX_CALL operator==(const update&, const update&);
  55. friend MONGOCXX_API bool MONGOCXX_CALL operator!=(const update&, const update&);
  56. };
  57. } // namespace result
  58. MONGOCXX_INLINE_NAMESPACE_END
  59. } // namespace mongocxx
  60. #include <mongocxx/config/postlude.hpp>