fix(NODE-5627): BulkWriteResult.insertedIds does not filter out _ids that are not actually inserted #3870
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description for NODE-5627
Before this change, on Node Driver Version 5.x,
BulkWriteResult.insertedIds
(1) would return an Object containing all attempted insertedIds, regardless of if any of the inserts failed. This affectsBulkWrite
andInsertMany
operations. After this PR is merged,BulkWriteResult.insertedIds
will reflect which _ids were actually inserted.Other Notes for Reviewers
InsertMany
operation; however, I was able to reproduce it generally for any insert operation that returnsBulkWriteResult
namelyBulkWrite
.BulkResult.insertedIds
will still contain unsuccessful inserted_ids
. TheBulkResult
class is not user facing.BulkResult.writeErrors
list property, rather than the actual direct insert response from the server, since the batch result does not contain_id
information.Is there new documentation needed for these changes?
Yes, it needs to be communicated to users that when an insert does not succeed through a
collection.bulkwrite()
orcollection.insertMany()
operation, it will no longer appear in the error's.result.insertedIds
What is the motivation for this change?
See release highlights.
Release Highlight
Inserted ids in bulk write only contain successful insertions - 5.x
Prior to this fix the bulk write error's
insertedIds
field contained ids of all attempted inserts in a bulk operation.When a
bulkwrite()
or aninsertMany()
operation rejects one or more inserts, throwing an error, the error'sBulkWriteResult
property will be filtered to only contain successfully inserted ids (ex:error.result.insertedIds
).Bug Description
Previous Behavior
The error's
.result.insertedIds
does includes all attempted inserts, regardless of if they failed or not.New Behavior
The error's
.result.insertedIds
does not include unsuccessful inserts.Namely,
Checklist
npm run check:lint
scripttype(NODE-xxxx)[!]: description
feat(NODE-1234)!: rewriting everything in coffeescript