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

feat(bulk)!: add collation to FindOperators #2679

Merged
merged 5 commits into from
Dec 21, 2020

Conversation

emadum
Copy link
Contributor

@emadum emadum commented Dec 16, 2020

Adds a fluent builder method for the collation of filtered bulk writes.
Removes legacy support for raw statements from collection.bulkWrite.

NODE-2757

@emadum emadum changed the title refactor: add collation to bulk FindOperators feat: add collation to bulk FindOperators Dec 17, 2020
@emadum emadum changed the title feat: add collation to bulk FindOperators feat(bulk): add collation to FindOperators Dec 17, 2020
@emadum emadum marked this pull request as ready for review December 17, 2020 20:01
/** Add a multiple update operation to the bulk operation */
update(updateDocument: Document): BulkOperationBase {
/** @internal */
makeUpdateDocument(u: Document, multi: boolean): Document {
Copy link
Member

Choose a reason for hiding this comment

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

A few nits/questions:

  • is this making an UpdateStatement? Can we reuse this internal helper I introduced last week?
  • at very least I don't think this should be mounted on FindOperators since you're now effectively making it public API (despite the loose contract of @internal)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we reuse this internal helper I introduced last week?

Nice, I refactored to use the makeUpdateStatement and makeDeleteStatement helpers. Note that there were already helpers by that name in this file, which do a very similar thing but with slightly different behavior.

It would be nice to consolidate them, but for now I've renamed them to makeBulkUpdateStatement and makeBulkDeleteStatement. There are a few TODOs in there so I want to be careful about replacing them:

// NOTE: legacy support for a raw statement, consider removing
// TODO: this check should be done at command construction against a connection, not a topology

Regarding removing the legacy support for raw statements, would you have any concerns about that? 4.0 would probably be a good time for it.

Copy link
Contributor Author

@emadum emadum Dec 18, 2020

Choose a reason for hiding this comment

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

I went ahead with that consolidation, removed the legacy support for raw statements and fixed the tests we had using the legacy format, and updated the validation checks marked with TODOs to happen against a server rather than a topology.

Copy link
Member

Choose a reason for hiding this comment

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

Heck'n YES, I love it! I'd say make sure you take another trip through the API docs and tests to ensure that you're properly documenting the shape of what's accepted in bulk. Also, now that the "raw" form of the operations are no longer accepted I think you will want to add some validation to let users know that things have changed. Right now I think you'll be silently breaking their applications potentially, so good to add some tests that prove their apps will not break. Otherwise, I think this is a huge improvement for bulk, great job.

src/bulk/common.ts Outdated Show resolved Hide resolved
if (hasAtomicOperators(replacement)) {
throw new TypeError('Replacement document must not use atomic operators');
}
removeOne(): BulkOperationBase {
Copy link
Member

Choose a reason for hiding this comment

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

remind me, is there a ticket to remove these duplicated methods for v4?

Copy link
Contributor Author

@emadum emadum Dec 18, 2020

Choose a reason for hiding this comment

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

I wasn't able to find one, it's not in the main ticket tracking deprecation (NODE-2317). Do you think we should get rid of them?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think now's the time to do it!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added NODE-2978 so as to not scope creep more on this PR 👍

@emadum emadum changed the title feat(bulk): add collation to FindOperators feat(bulk)!: add collation to FindOperators Dec 18, 2020
@emadum emadum requested a review from mbroadst December 18, 2020 20:25
@emadum emadum force-pushed the NODE-2757/add-collation-to-bulk-find-operators branch from 55df13e to e0e6869 Compare December 18, 2020 21:35
@emadum emadum force-pushed the NODE-2757/add-collation-to-bulk-find-operators branch from e0e6869 to 85b8911 Compare December 18, 2020 21:50
if (hasAtomicOperators(replacement)) {
throw new TypeError('Replacement document must not use atomic operators');
}
removeOne(): BulkOperationBase {
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think now's the time to do it!


remove(): BulkOperationBase {
return this.delete();
this.bulkOperation.s.currentOp.collation = collation;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this should expand the scope of this PR, but I just wanted to comment on something so you can keep it in mind. We have "builders" for a number of things in the driver, specifically for bulk and cursors. I think it would be really great for readability/maintainability if you were doing them all the same way. The bulk builders need a lot of work, and are confusingly coupled, but I think you could use a [kBuiltOptions] approach here (or better yet, wrap [kBuiltOptions] in some well-typed methods like addToCurrentOperation that you can reuse as a toolkit across all "builders" in the codebase).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed that it'd be nice to have a single approach to built options. There's already a new ticket for adding a builder method for arrayFilters (NODE-2751), so perhaps we should prioritize this work as part of NODE-2734.

@emadum emadum merged commit a41d503 into master Dec 21, 2020
@emadum emadum deleted the NODE-2757/add-collation-to-bulk-find-operators branch December 21, 2020 20:05
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.

3 participants