File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ namespace mongo {
27
27
} // namespace
28
28
29
29
InsertWriteOperation::InsertWriteOperation (const BSONObj& doc)
30
- : _doc(doc)
30
+ : _doc(_ensureId( doc) )
31
31
{}
32
32
33
33
WriteOpType InsertWriteOperation::operationType () const {
@@ -63,4 +63,14 @@ namespace mongo {
63
63
obj->appendElements (_doc);
64
64
}
65
65
66
+ BSONObj InsertWriteOperation::_ensureId (const BSONObj& doc) {
67
+ if (doc.hasField (" _id" ))
68
+ return doc;
69
+
70
+ BSONObjBuilder bob;
71
+ bob.append (" _id" , OID::gen ());
72
+ bob.appendElements (doc);
73
+ return bob.obj ();
74
+ }
75
+
66
76
} // namespace mongo
Original file line number Diff line number Diff line change @@ -36,6 +36,8 @@ namespace mongo {
36
36
virtual void appendSelfToBSONObj (BSONObjBuilder* obj) const ;
37
37
38
38
private:
39
+ static BSONObj _ensureId (const BSONObj& doc);
40
+
39
41
const BSONObj _doc;
40
42
};
41
43
You can’t perform that action at this time.
0 commit comments