-
Type:
Task
-
Resolution: Works as Designed
-
Priority:
Major - P3
-
None
-
Affects Version/s: 2.2.22
-
Component/s: MongoDB 3.4
-
Environment:Ubuntu 16.04 x64, Dual-Core E5700, 4 GB DDR, Using via Mongoose `Model.collection.initializeUnorderedBulkOp()` notation, Redis and MongoDB are on the same machine and are share the system resources (20% of the RAM is used by Redis).
When performing bulk insert operations the error below occurs:
MongoError: E11000 duplicate key error collection: ... index: _id_ dup key
I expect that on every insert of the bulk operation MongoDB gives a new ObjectId for the new inserting document.
So I guess there is a lack of documentation or is a bug. Or it is incompetence of me to find the relevant official documentation.
My pseudo code:
var bulk = MyModel.collection.initializeUnorderedBulkOp() var i = 0 function repeatMe (call) { i++ bulk.insert(doc) if (i % 1000 == 0) { bulk.execute((err, res) => { bulk = MyModel.collection.initializeUnorderedBulkOp() callback(err) }) } }