Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-1363

InsertMany returns InsertedID's from insertions that errored

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.3.3
    • Affects Version/s: 1.1.2
    • Component/s: CRUD
    • None

      When inserting a document using Collection.InsertMany that fails due to a unique index constraint the resulting mongo.InsertManyResults reports the documents ID as being Inserted.

      It looks like that the results are actually computed before issuing the BulkWrite operation and never updated according to its outcome. Cleary, the results of the BulkWrite should be taken into account and only the IDs of successfully inserted documents may be returned together with the last error.

      Here the result from the mentioned call:

      &mongo.InsertManyResult{
          InsertedIDs: {
              primitive.ObjectID{0x5d, 0xab, 0x36, 0x86, 0xf, 0xa5, 0xbc, 0x20, 0x30, 0xd6, 0x1c, 0x8},
          },
      } mongo.BulkWriteException{
          WriteConcernError: (*mongo.WriteConcernError)(nil),
          WriteErrors:       {
              {
                  WriteError: mongo.WriteError{Index:0, Code:11000, Message:"E11000 duplicate key error collection: test.test index: _id_ dup key: { : ObjectId('5dab36860fa5bc2030d61c08') }"},
                  Request:    nil,
              },
          },
      }
      

            Assignee:
            isabella.siu@mongodb.com Isabella Siu (Inactive)
            Reporter:
            joel@sternenbauer.com Joël Gähwiler
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: