-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Bulk API
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 from bulkWriteResult.insertedIds
- New tests
- Add perf testing for happy path and error path
- Test on inserts with multiple errors and singular error
- Test on unordered and ordered inserts with errors
- Update bulkWrite docs manual
- Minimize effect on performance
- 5.x and 6.x support
- backported by
-
NODE-5625 [v5.x BACKPORT] BulkWriteResult.insertedIds does not reflect actual inserted documents in insertMany error
- Closed
- is duplicated by
-
NODE-5625 [v5.x BACKPORT] BulkWriteResult.insertedIds does not reflect actual inserted documents in insertMany error
- Closed
- is related to
-
NODE-5932 BulkWriteResult show incorrect insertedIds on certain errors when using bulk insert (insertMany)
- Backlog
-
DRIVERS-2725 BulkWriteResult.insertedIds does not reflect actual inserted documents
- Backlog