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 {
2727 } // namespace
2828
2929 InsertWriteOperation::InsertWriteOperation (const BSONObj& doc)
30- : _doc(doc)
30+ : _doc(_ensureId( doc) )
3131 {}
3232
3333 WriteOpType InsertWriteOperation::operationType () const {
@@ -63,4 +63,14 @@ namespace mongo {
6363 obj->appendElements (_doc);
6464 }
6565
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+
6676} // namespace mongo
Original file line number Diff line number Diff line change @@ -36,6 +36,8 @@ namespace mongo {
3636 virtual void appendSelfToBSONObj (BSONObjBuilder* obj) const ;
3737
3838 private:
39+ static BSONObj _ensureId (const BSONObj& doc);
40+
3941 const BSONObj _doc;
4042 };
4143
You can’t perform that action at this time.
0 commit comments