Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-1171

Collection.insertMany() fails when given an array of duplicate objects

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.2.33
    • Component/s: MongoDB 3.4
    • Environment:
      Windows 10 x64, Node v8.8.0

      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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            kevipapo1 Kevin Snyder
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: