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

InsertMany returns InsertedID's from insertions that errored

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 1.1.2
    • Fix Version/s: 1.3.3
    • Component/s: CRUD
    • Labels:
      None

      Description

      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,
              },
          },
      }
      

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: