-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
refactor: reuse sort logic between Query and Aggregate #15818
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
base: master
Are you sure you want to change the base?
Conversation
|
Hey @vkarpov15, |
|
@AbdelrahmanHafez @hasezoey Can you please have a look at the PR and let me know if anything needs to be changed. |
hasezoey
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.
Looks mostly good to me, though this includes a bunch of style changes which should not be part of this PR; please fix that.
|
@AbdelrahmanHafez @hasezoey Can you again run tests this time it would pass. |
hasezoey
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.
Looks good to me, though still contains some unrelated style changes (which arguably should be added to the lint, if possible).
| this.op === 'countDocuments' || | ||
| this.op === 'find' || | ||
| this.op === 'findOne' || | ||
| this.op === 'deleteMany' || | ||
| this.op === 'deleteOne' || | ||
| this.op === 'findOneAndDelete' || | ||
| this.op === 'remove') { |
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.
Those are also unrelated style changes, though from what i can tell, it is not caught by the lint currently.
vkarpov15
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.
Overall this looks reasonable, but please undo the unrelated style changes
vkarpov15
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.
Please undo all the unrelated style changes
This PR refactors Aggregate.prototype.sort to reuse the sort argument parsing logic from Query.prototype.sort, addressing an existing TODO in lib/aggregate.js
I extracted the sort parsing logic into a new shared helper function castSort (located in lib/helpers/query/castSort.js) and updated both Query and Aggregate to use it.
This reduces code duplication and ensures consistent behavior between the two classes. As a side effect, Aggregate.prototype.sort now supports Map and Array arguments, matching the capabilities of Query.prototype.sort.
Examples
Aggregate.prototype.sort now supports Maps and Arrays of Arrays, which were previously only supported by Query.prototype.sort: