MongoDB C++ Driver  legacy-1.1.2
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 
23 namespace mongo {
24 
25 class BSONObj;
26 class BSONElement;
27 class StringData;
28 class WriteOperation;
29 
33 class MONGO_CLIENT_API WriteResult {
34  friend class WireProtocolWriter;
35  friend class CommandWriter;
36  friend class BulkOperationBuilder;
37  friend class DBClientBase;
38 
39 public:
43  WriteResult();
44 
45  //
46  // Introspection
47  //
48 
54  bool hasErrors() const;
55 
62  bool hasWriteErrors() const;
63 
70  bool hasWriteConcernErrors() const;
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 
143 private:
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
A StringData object wraps a 'const string&' or a 'const char*' without copying its contents...
Definition: string_data.h:43
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
Class for constructing and executing bulk operations against MongoDB via a fluent API...
Definition: bulk_operation_builder.h:54
Class representing the result of a write operations sent to the server.
Definition: write_result.h:33
Definition: wire_protocol_writer.h:24
BSONElement represents an "element" in a BSONObj.
Definition: bsonelement.h:55
Definition: command_writer.h:24
abstract class that implements the core db operations
Definition: dbclientinterface.h:1422
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary represent...
Definition: bsonobj.h:78