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

types: make lean() not clobber result type for updateOne(), etc. #13389

Merged
merged 1 commit into from May 10, 2023

Conversation

vkarpov15
Copy link
Collaborator

Fix #13382

Summary

Doing Model.updateOne().lean() returns an incorrect type: has _id, etc. With this change, queries now have a QueryOp generic that they can use to check the current query op. With this change, Model.deleteOne().lean(), etc. all reflect their runtime behavior: lean() is a no-op.

Examples

Copy link
Collaborator

@AbdelrahmanHafez AbdelrahmanHafez left a comment

Choose a reason for hiding this comment

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

LGTM, thanks. 👍

I think it's worth taking a note to deprecate using lean on non-find operations like deleteOne/countDocuments in both TS types and JS runtime, it doesn't make sense to call them with lean.

Copy link
Collaborator

@AbdelrahmanHafez AbdelrahmanHafez left a comment

Choose a reason for hiding this comment

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

LGTM, thanks. 👍

I think it's worth taking a note to deprecate using lean on non-find operations like deleteOne/countDocuments in both TS types and JS runtime, it doesn't make sense to call them with lean.

@vkarpov15
Copy link
Collaborator Author

Potentially. As a general rule of thumb, Mongoose doesn't throw errors on unrecognized or unused options, so throwing an error when using lean() on an operation that doesn't handle documents would be a bit inconsistent. I opened an issue to consider that for the future.

@vkarpov15 vkarpov15 merged commit f8244bd into master May 10, 2023
3 checks passed
@vkarpov15 vkarpov15 deleted the vkarpov15/gh-13382 branch May 10, 2023 20:56
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.

ts def of updateOne&findOneAndUpdate returns FlattenMap instead of UpdateWriteOpResult, when lean() is used
3 participants