Skip to content
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

Merged

Conversation

HanaPearlman
Copy link
Contributor

This PR makes BulkWriteError conform to the CRUD spec by adding the necessary fields required by the spec tests to the class and renames BulkWriteError to MongoBulkWriteError.

NODE-1989, NODE-2331

@HanaPearlman HanaPearlman requested review from nbbeeken, mbroadst and emadum and removed request for nbbeeken and mbroadst November 13, 2020 20:21
Copy link
Contributor

@emadum emadum left a 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.

/** 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) {
Copy link
Contributor

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.


this.insertedCount = result?.insertedCount;
this.matchedCount = result?.matchedCount;
this.modifiedCount = result?.modifiedCount || 0;
Copy link
Contributor

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.

result?: BulkWriteResult;

/** Creates a new BulkWriteError */
/** Number of documents inserted. */
insertedCount?: number;
Copy link
Contributor

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.

Copy link
Contributor

@nbbeeken nbbeeken left a 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!

@HanaPearlman HanaPearlman requested a review from emadum November 18, 2020 13:59
Copy link
Member

@mbroadst mbroadst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@HanaPearlman HanaPearlman force-pushed the NODE-1989/master/bulk-write-error branch from a832898 to b806fa2 Compare November 19, 2020 13:59
@HanaPearlman HanaPearlman merged commit 7aa3567 into mongodb:master Nov 19, 2020
@HanaPearlman HanaPearlman deleted the NODE-1989/master/bulk-write-error branch November 19, 2020 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants