MongoDB C++ Driver  legacy-1.0.3
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 
35  friend class WireProtocolWriter;
36  friend class CommandWriter;
37  friend class BulkOperationBuilder;
38 
39  public:
40 
44  WriteResult();
45 
46  //
47  // Introspection
48  //
49 
55  bool hasErrors() const;
56 
63  bool hasWriteErrors() const;
64 
71  bool hasWriteConcernErrors() const;
72 
80  bool hasModifiedCount() const;
81 
82 
83  //
84  // Data
85  //
86 
92  int nInserted() const;
93 
99  int nUpserted() const;
100 
106  int nMatched() const;
107 
113  int nModified() const;
114 
120  int nRemoved() const;
121 
127  const std::vector<BSONObj>& upserted() const;
128 
129 
130  //
131  // Errors Data
132  //
133 
137  const std::vector<BSONObj>& writeErrors() const;
138 
142  const std::vector<BSONObj>& writeConcernErrors() const;
143 
144  private:
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
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