MongoDB C++ Driver legacy-1.1.2
Loading...
Searching...
No Matches
write_result.h
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 */
15
16#pragma once
17
18#include <vector>
19
20#include "mongo/client/export_macros.h"
21#include "mongo/util/net/operation.h"
22
23namespace mongo {
24
25class BSONObj;
26class BSONElement;
27class StringData;
28class WriteOperation;
29
33class MONGO_CLIENT_API WriteResult {
34 friend class WireProtocolWriter;
35 friend class CommandWriter;
36 friend class BulkOperationBuilder;
37 friend class DBClientBase;
38
39public:
44
45 //
46 // Introspection
47 //
48
54 bool hasErrors() const;
55
62 bool hasWriteErrors() const;
63
71
79 bool hasModifiedCount() const;
80
81
82 //
83 // Data
84 //
85
91 int nInserted() const;
92
98 int nUpserted() const;
99
105 int nMatched() const;
106
112 int nModified() const;
113
119 int nRemoved() const;
120
126 const std::vector<BSONObj>& upserted() const;
127
128
129 //
130 // Errors Data
131 //
132
136 const std::vector<BSONObj>& writeErrors() const;
137
141 const std::vector<BSONObj>& writeConcernErrors() const;
142
143private:
144 void _mergeWriteConcern(const BSONObj& result);
145 void _mergeCommandResult(const std::vector<WriteOperation*>& ops, const BSONObj& result);
146 void _mergeGleResult(const std::vector<WriteOperation*>& ops, const BSONObj& result);
147
148 void _check(bool throwSoftErrors);
149 void _setModified(const BSONObj& result);
150 int _getIntOrDefault(const BSONObj& obj, const StringData& field, const int defaultValue = 0);
151
152 int _createUpserts(const BSONElement& upsert, const std::vector<WriteOperation*>& ops);
153 void _createUpsert(const BSONElement& upsert, const std::vector<WriteOperation*>& ops);
154 void _createWriteError(const BSONObj& error, const std::vector<WriteOperation*>& ops);
155 void _createWriteConcernError(const BSONObj& error);
156
157 int _nInserted;
158 int _nUpserted;
159 int _nMatched;
160 int _nModified;
161 int _nRemoved;
162
163 std::vector<BSONObj> _upserted;
164 std::vector<BSONObj> _writeErrors;
165 std::vector<BSONObj> _writeConcernErrors;
166
167 bool _hasModifiedCount;
168 bool _requiresDetailedInsertResults;
169};
170
171} // namespace mongo
BSONElement represents an "element" in a BSONObj.
Definition bsonelement.h:55
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary representa...
Definition bsonobj.h:78
Class for constructing and executing bulk operations against MongoDB via a fluent API.
Definition bulk_operation_builder.h:54
Definition command_writer.h:24
abstract class that implements the core db operations
Definition dbclientinterface.h:1422
A StringData object wraps a 'const string&' or a 'const char*' without copying its contents.
Definition string_data.h:43
Definition wire_protocol_writer.h:24
Class representing the result of a write operations sent to the server.
Definition write_result.h:33
int nUpserted() const
The number of documents that were upserted.
WriteResult()
Creates an empty write result.
bool hasWriteConcernErrors() const
Returns true if there have been write concern errors.
const std::vector< BSONObj > & writeConcernErrors() const
Vector with the write concern errors that occurred.
int nMatched() const
The number of documents that were matched.
int nModified() const
The number of documents that were modified.
bool hasErrors() const
Returns true if there have been write errors of any kind.
int nRemoved() const
The number of documents that were removed.
bool hasWriteErrors() const
Returns true if there have been write errors.
const std::vector< BSONObj > & upserted() const
The information about documents that were upserted.
bool hasModifiedCount() const
Returns true if the number of modified documents is available.
int nInserted() const
The number of documents that were inserted.
const std::vector< BSONObj > & writeErrors() const
Vector with the write errors that occurred.
Utility functions for parsing numbers from strings.
Definition compare_numbers.h:20