userver
C++ Async Framework
Loading...
Searching...
No Matches
write_result.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/storages/mongo/write_result.hpp
4
/// @brief @copybrief storages::mongo::WriteResult
5
6
#
include
<
cstddef
>
7
#
include
<
optional
>
8
#
include
<
unordered_map
>
9
#
include
<
vector
>
10
11
#
include
<
userver
/
formats
/
bson
/
document
.
hpp
>
12
#
include
<
userver
/
formats
/
bson
/
value
.
hpp
>
13
#
include
<
userver
/
storages
/
mongo
/
mongo_error
.
hpp
>
14
15
USERVER_NAMESPACE_BEGIN
16
17
namespace
storages::mongo {
18
19
/// @brief MongoDB write operation result
20
class
WriteResult
{
21
public
:
22
/// Creates an empty write result
23
WriteResult
() =
default
;
24
25
/// @cond
26
/// Wraps provided write result, internal use only
27
explicit
WriteResult(formats::
bson
::
Document
,
MongoError
error);
28
/// @endcond
29
30
/// @name Affected document counters
31
/// Valid only for acknowledged writes, i.e. non-zero write concern
32
/// @{
33
size_t InsertedCount()
const
;
34
size_t MatchedCount()
const
;
35
size_t ModifiedCount()
const
;
36
size_t UpsertedCount()
const
;
37
size_t DeletedCount()
const
;
38
/// @}
39
40
/// Map of `_id` values of upserted documents by operation (document) index
41
std::unordered_map<size_t, formats::
bson
::
Value
>
UpsertedIds
()
const
;
42
43
/// The document returned by FindAnd* operation if any
44
std::optional<formats::
bson
::
Document
>
FoundDocument
()
const
;
45
46
/// @brief Map of server errors by operation (document) index.
47
///
48
/// For example, storages::mongo::Collection::InsertMany() with
49
/// storages::mongo::options::Unordered and
50
/// storages::mongo::options::SuppressServerExceptions option would produce a
51
/// WriteResult with WriteResult::ServerErrors() containing information about
52
/// failed insertions.
53
///
54
/// @see options::SuppressServerExceptions
55
std::unordered_map<size_t,
MongoError
>
ServerErrors
()
const
;
56
57
/// @brief Write concern errors
58
/// @see options::SuppressServerExceptions
59
std::vector<
MongoError
>
WriteConcernErrors
()
const
;
60
61
/// @brief If the operation is not completed successfully,
62
/// an error that caused it will be returned.
63
///
64
/// It is necessary to check whether an error is set up.
65
///
66
/// @see options::SuppressServerExceptions
67
const
MongoError
&
OperationError
()
const
;
68
69
private
:
70
formats::
bson
::
Document
value_;
71
MongoError
error_;
72
};
73
74
}
// namespace storages::mongo
75
76
USERVER_NAMESPACE_END
userver
storages
mongo
write_result.hpp
Generated on Thu May 21 2026 16:21:27 for userver by
Doxygen
1.13.2