-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Bulk API
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