bulk_write.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 <map>
  17. #include <vector>
  18. #include <bsoncxx/document/value.hpp>
  19. #include <bsoncxx/document/view.hpp>
  20. #include <bsoncxx/types.hpp>
  21. #include <mongocxx/config/prelude.hpp>
  22. namespace mongocxx {
  23. MONGOCXX_INLINE_NAMESPACE_BEGIN
  24. namespace result {
  25. ///
  26. /// Class representing the result of a MongoDB bulk write operation.
  27. ///
  28. class MONGOCXX_API bulk_write {
  29. public:
  30. using id_map = std::map<std::size_t, bsoncxx::document::element>;
  31. // This constructor is public for testing purposes only
  32. explicit bulk_write(bsoncxx::document::value raw_response);
  33. ///
  34. /// Gets the number of documents that were inserted during this operation.
  35. ///
  36. /// @return The number of documents that were inserted.
  37. ///
  38. std::int32_t inserted_count() const;
  39. ///
  40. /// Gets the number of documents that were matched during this operation.
  41. ///
  42. /// @return The number of documents that were matched.
  43. ///
  44. std::int32_t matched_count() const;
  45. ///
  46. /// Gets the number of documents that were modified during this operation.
  47. ///
  48. /// @return The number of documents that were modified.
  49. ///
  50. /// @throws with server versions below 2.6 due to the field `nModified` not being returned.
  51. ///
  52. std::int32_t modified_count() const;
  53. ///
  54. /// Gets the number of documents that were deleted during this operation.
  55. ///
  56. /// @return The number of documents that were deleted.
  57. ///
  58. std::int32_t deleted_count() const;
  59. ///
  60. /// Gets the number of documents that were upserted during this operation.
  61. ///
  62. /// @return The number of documents that were upserted.
  63. ///
  64. std::int32_t upserted_count() const;
  65. ///
  66. /// Gets the ids of the upserted documents.
  67. ///
  68. /// @note The returned id_map must not be accessed after the bulk_write object is destroyed.
  69. /// @return A map from bulk write index to _id field for upserted documents.
  70. ///
  71. id_map upserted_ids() const;
  72. private:
  73. MONGOCXX_PRIVATE bsoncxx::document::view view() const;
  74. bsoncxx::document::value _response;
  75. friend MONGOCXX_API bool MONGOCXX_CALL operator==(const bulk_write&, const bulk_write&);
  76. friend MONGOCXX_API bool MONGOCXX_CALL operator!=(const bulk_write&, const bulk_write&);
  77. };
  78. } // namespace result
  79. MONGOCXX_INLINE_NAMESPACE_END
  80. } // namespace mongocxx
  81. #include <mongocxx/config/postlude.hpp>