insert_one.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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/array/value.hpp>
  16. #include <bsoncxx/types.hpp>
  17. #include <bsoncxx/types/bson_value/view.hpp>
  18. #include <mongocxx/result/bulk_write.hpp>
  19. #include <mongocxx/config/prelude.hpp>
  20. namespace mongocxx {
  21. MONGOCXX_INLINE_NAMESPACE_BEGIN
  22. namespace result {
  23. /// Class representing the result of a MongoDB insert operation.
  24. class MONGOCXX_API insert_one {
  25. public:
  26. // This constructor is public for testing purposes only
  27. insert_one(result::bulk_write result, bsoncxx::types::bson_value::view inserted_id);
  28. ///
  29. /// Returns the bulk write result for this insert operation.
  30. ///
  31. /// @return The raw bulk write result.
  32. ///
  33. const result::bulk_write& result() const;
  34. ///
  35. /// Gets the _id of the inserted document.
  36. ///
  37. /// @return The value of the _id field for the inserted document.
  38. ///
  39. const bsoncxx::types::bson_value::view& inserted_id() const;
  40. private:
  41. result::bulk_write _result;
  42. // Array with a single element, containing the value of the _id field for the inserted document.
  43. bsoncxx::array::value _inserted_id_owned;
  44. // Points into _inserted_id_owned.
  45. bsoncxx::types::bson_value::view _inserted_id;
  46. friend MONGOCXX_API bool MONGOCXX_CALL operator==(const insert_one&, const insert_one&);
  47. friend MONGOCXX_API bool MONGOCXX_CALL operator!=(const insert_one&, const insert_one&);
  48. };
  49. } // namespace result
  50. MONGOCXX_INLINE_NAMESPACE_END
  51. } // namespace mongocxx
  52. #include <mongocxx/config/postlude.hpp>