Github   Telegram
Loading...
Searching...
No Matches
write_result.hpp
1#pragma once
2
3#include <cstddef>
4#include <optional>
5#include <unordered_map>
6#include <vector>
7
8#include <userver/formats/bson/document.hpp>
9#include <userver/formats/bson/value.hpp>
10#include <userver/storages/mongo/mongo_error.hpp>
11
12USERVER_NAMESPACE_BEGIN
13
14namespace storages::mongo {
15
16/// MongoDB write operation result
17class WriteResult {
18 public:
19 /// Creates an empty write result
20 WriteResult() = default;
21
22 /// @cond
23 /// Wraps provided write result, internal use only
24 explicit WriteResult(formats::bson::Document);
25 /// @endcond
26
27 /// @name Affected document counters
28 /// Valid only for acknowledged writes, i.e. non-zero write concern
29 /// @{
30 size_t InsertedCount() const;
31 size_t MatchedCount() const;
32 size_t ModifiedCount() const;
33 size_t UpsertedCount() const;
34 size_t DeletedCount() const;
35 /// @}
36
37 /// Map of `_id` values of upserted documents by operation (document) index
39
40 /// The document returned by FindAnd* operation if any
41 std::optional<formats::bson::Document> FoundDocument() const;
42
43 /// @brief Map of server errors by operation (document) index
44 /// @see options::SuppressServerExceptions
46
47 /// @brief Write concern errors
48 /// @see options::SuppressServerExceptions
50
51 private:
52 formats::bson::Document value_;
53};
54
55} // namespace storages::mongo
56
57USERVER_NAMESPACE_END