Uploaded image for project: 'Drivers'
  1. Drivers
  2. DRIVERS-2725

BulkWriteResult.insertedIds does not reflect actual inserted documents

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Component/s: CRUD
    • Labels:
    • Needed


      Currently, the drivers specification for BulkWriteResult provides an optional property `insertedIds` (see CRUD spec, MongoDB manual).

      A user on Version 5.6.0 of the Node Driver reported the following bug on BulkWriteResult.insertedIds: If there are writeErrors and an _id is not correctly inserted, it will still incorrectly appear in the insertedIds Object.

      This bug likely reproduce on other drivers variations that support BulkWriteResult.insertedIds.


      Who is the affected end user?

      The affected end user is any user using BulkWrite or InsertMany with inserts that contain any errors.

      How does this affect the end user?

      In the event of an error case, the user will be confused as to which _ids were inserted. This is because BulkWriteResult.writeErrors will signal that certain inserts were unsuccessful, but BulkWriteResult.insertedIds will include all attempted inserts.

      This can lead the user to be misinformed on which inserts were successful.

      How likely is it that this problem or use case will occur?

      Edge Case

      If the problem does occur, what are the consequences and how severe are they?

      Misinformation, potentially minor

      Is this issue urgent?


      Is this ticket required by a downstream team?

      May affect Mongosh

      Is this ticket only for tests?


      Acceptance Criteria

      • BulkWrite and InsertMany support insertedIds correctly, in that insertedIds only includes index and _id pairs that were actually inserted
      • Tests cover unordered and ordered inserts, as well as inserts with multiple errors

            Unassigned Unassigned
            aditi.khare@mongodb.com Aditi Khare
            0 Vote for this issue
            7 Start watching this issue