-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix: make MongoBulkWriteError conform to CRUD spec #2621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: make MongoBulkWriteError conform to CRUD spec #2621
Conversation
emadum
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I think we can take this PR as an opportunity to tighten up some properties which are currently optional but don't need to be.
src/bulk/common.ts
Outdated
| upsertedIds?: { [key: number]: ObjectId }; | ||
|
|
||
| /** Creates a new MongoBulkWriteError */ | ||
| constructor(error?: AnyError, result?: BulkWriteResult) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should make the error and result properties/constructor options non-optional. These errors are always constructed with both arguments.
src/bulk/common.ts
Outdated
|
|
||
| this.insertedCount = result?.insertedCount; | ||
| this.matchedCount = result?.matchedCount; | ||
| this.modifiedCount = result?.modifiedCount || 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need to provide a default here, modifiedCount is already guaranteed to be a number in BulkWriteResult.
src/bulk/common.ts
Outdated
|
|
||
| /** Creates a new BulkWriteError */ | ||
| /** Number of documents inserted. */ | ||
| insertedCount?: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If result isn't optional (see lower comment) none of these new properties need to be optional either.
nbbeeken
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eric's suggestions seem to cover it, lgtm!
mbroadst
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
a832898 to
b806fa2
Compare
This PR makes
BulkWriteErrorconform to the CRUD spec by adding the necessary fields required by the spec tests to the class and renamesBulkWriteErrortoMongoBulkWriteError.NODE-1989, NODE-2331