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

[v5.x BACKPORT] BulkWriteResult.insertedIds does not reflect actual inserted documents in insertMany error

    • 2
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Backport NODE-5421 to v5.x.

      Parent Ticket Description:

      When using `insertMany`, if there is a write error for one of the insert operations, and it is not actually inserted to the DB, It's _id still appear in the `insertedIds` object

      Using NodeJS driver version 5.6.0. This likely reproduce on other drivers variations

      Steps to reproduce (example):

      1. Define a unique index `name` on collection `A`.
      2. use `insertMany` to insert two documents each having the same `name`
      3. An error will be thrown (because of the duplicate value for a unique index) - 
      use `catch(error=> {...})` to catch the error.
      Look at `error.result.insertedIds` (log it) - the last _id appearing there (under index '1' of the object) was not actually inserted to the DB. It should not appear there, as the name `insertedIds` implies ids of actually inserted documents.

      Notes:
      `insertedCount` will reflect correctly the number of inserted documents (1).
      iterating over write errors (e.g. using getWriteErrors()) - will correctly show the duplicate key error and its details.
       

      AC

      • Filter out any IDs that aren't actually inserted
      • New tests
      • Update bulkWrite docs manual
      • Minimize effect on performance

            Assignee:
            Unassigned Unassigned
            Reporter:
            dbeng-pm-bot PM Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: