userver: userver/storages/mongo/write_result.hpp Source File
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 ///
45 /// For example, storages::mongo::Collection::InsertMany() with
46 /// storages::mongo::options::Unordered and
47 /// storages::mongo::options::SuppressServerExceptions option would produce a
48 /// WriteResult with WriteResult::ServerErrors() containing information about
49 /// failed insertions.
50 ///
51 /// @see options::SuppressServerExceptions
53
54 /// @brief Write concern errors
55 /// @see options::SuppressServerExceptions
57
58 private:
59 formats::bson::Document value_;
60};
61
62} // namespace storages::mongo
63
64USERVER_NAMESPACE_END