MongoDB C++ Driver  legacy-1.0.7
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 
38 public:
42  WriteResult();
43 
44  //
45  // Introspection
46  //
47 
53  bool hasErrors() const;
54 
61  bool hasWriteErrors() const;
62 
69  bool hasWriteConcernErrors() const;
70 
78  bool hasModifiedCount() const;
79 
80 
81  //
82  // Data
83  //
84 
90  int nInserted() const;
91 
97  int nUpserted() const;
98 
104  int nMatched() const;
105 
111  int nModified() const;
112 
118  int nRemoved() const;
119 
125  const std::vector<BSONObj>& upserted() const;
126 
127 
128  //
129  // Errors Data
130  //
131 
135  const std::vector<BSONObj>& writeErrors() const;
136 
140  const std::vector<BSONObj>& writeConcernErrors() const;
141 
142 private:
143  void _mergeCommandResult(const std::vector<WriteOperation*>& ops, const BSONObj& result);
144  void _mergeGleResult(const std::vector<WriteOperation*>& ops, const BSONObj& result);
145 
146  void _check(bool throwSoftErrors);
147  void _setModified(const BSONObj& result);
148  int _getIntOrDefault(const BSONObj& obj, const StringData& field, const int defaultValue = 0);
149 
150  int _createUpserts(const BSONElement& upsert, const std::vector<WriteOperation*>& ops);
151  void _createUpsert(const BSONElement& upsert, const std::vector<WriteOperation*>& ops);
152  void _createWriteError(const BSONObj& error, const std::vector<WriteOperation*>& ops);
153  void _createWriteConcernError(const BSONObj& error);
154 
155  int _nInserted;
156  int _nUpserted;
157  int _nMatched;
158  int _nModified;
159  int _nRemoved;
160 
161  std::vector<BSONObj> _upserted;
162  std::vector<BSONObj> _writeErrors;
163  std::vector<BSONObj> _writeConcernErrors;
164 
165  bool _hasModifiedCount;
166  bool _requiresDetailedInsertResults;
167 };
168 
169 } // namespace mongo
the main MongoDB namespace
Definition: bulk_operation_builder.h:24
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
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary represent...
Definition: bsonobj.h:78