-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix: make MongoBulkWriteError conform to CRUD spec #2621
Conversation
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
/** Upserted document generated Id's, hash key is the index of the originating operation */ | ||
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
result?: BulkWriteResult; | ||
|
||
/** 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.
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!
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
BulkWriteError
conform to the CRUD spec by adding the necessary fields required by the spec tests to the class and renamesBulkWriteError
toMongoBulkWriteError
.NODE-1989, NODE-2331