-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Minor - P4
-
None
-
Affects Version/s: 2.2.33
-
Component/s: MongoDB 3.4
-
Environment:Windows 10 x64, Node v8.8.0
-
Empty show more show less
Collection.insertMany() throws E11000 when attempting to insert an array that contains duplicate objects.
You can reproduce the bug with the following code:
const mongodb = require('mongodb'); // Set up array of objects let o = { name: 'Joe' }; let a = [o, o, o]; // Insert into the database mongodb.MongoClient.connect('mongodb://localhost:27017/database', (err, db) => { let collection = db.collection('someCollection'); collection.insertMany(a).catch((error) => { console.log(error.message); }); });
If each object in the array is unique (i.e. deep copy as opposed to shallow copy) the operation works as expected.
If this is intended behavior, then it should at least be clearly documented here.