-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathWriteConcernResult.cs
104 lines (95 loc) · 2.93 KB
/
WriteConcernResult.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* Copyright 2010-present MongoDB Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using MongoDB.Bson;
using MongoDB.Driver.Core.Misc;
namespace MongoDB.Driver
{
/// <summary>
/// Represents the results of an operation performed with an acknowledged WriteConcern.
/// </summary>
public class WriteConcernResult
{
// fields
private readonly BsonDocument _response;
// constructors
/// <summary>
/// Initializes a new instance of the <see cref="WriteConcernResult"/> class.
/// </summary>
/// <param name="response">The response.</param>
public WriteConcernResult(BsonDocument response)
{
_response = Ensure.IsNotNull(response, nameof(response));
}
// properties
/// <summary>
/// Gets the number of documents affected.
/// </summary>
public long DocumentsAffected
{
get
{
BsonValue value;
return _response.TryGetValue("n", out value) ? value.ToInt64() : 0;
}
}
/// <summary>
/// Gets whether the result has a LastErrorMessage.
/// </summary>
public bool HasLastErrorMessage
{
get { return _response.GetValue("err", false).ToBoolean(); }
}
/// <summary>
/// Gets the last error message (null if none).
/// </summary>
public string LastErrorMessage
{
get
{
var err = _response.GetValue("err", false);
return (err.ToBoolean()) ? err.ToString() : null;
}
}
/// <summary>
/// Gets the _id of an upsert that resulted in an insert.
/// </summary>
public BsonValue Upserted
{
get
{
return _response.GetValue("upserted", null);
}
}
/// <summary>
/// Gets whether the last command updated an existing document.
/// </summary>
public bool UpdatedExisting
{
get
{
var updatedExisting = _response.GetValue("updatedExisting", false);
return updatedExisting.ToBoolean();
}
}
/// <summary>
/// Gets the wrapped result.
/// </summary>
public BsonDocument Response
{
get { return _response; }
}
}
}