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(query): delay converting documents into POJOs until query execution, allow querying subdocuments with defaults disabled #13522

Merged
merged 1 commit into from Jun 19, 2023

Conversation

vkarpov15
Copy link
Collaborator

Fix #13512

Summary

This change has a bit wider of a surface area than I'd like, but it should be good for performance and developer experience. The problem in #13512 is that Mongoose converts any query filters to POJOs first, and then recasts subdocument path POJOs back into subdocuments, before converting them to POJOs again; and loses the original settings so there's no way to execute a query on a subdocument path without applying defaults.

With this change, Mongoose will only convert documents in query filters to POJOs once, using the toBSON() function. Besides fixing #13512, this should make Mongoose faster in cases where you have subdocuments in query filters.

The only potential risk is that we're copying documents as POJOs somewhere. That's why I had to add source = source.toObject(internalToObjectOptions);.

Examples

…ion, allow querying subdocuments with defaults disabled

Fix #13512
@vkarpov15 vkarpov15 added this to the 7.4.0 milestone Jun 19, 2023
@vkarpov15 vkarpov15 merged commit dda72c6 into 7.4 Jun 19, 2023
34 checks passed
@AbdelrahmanHafez AbdelrahmanHafez deleted the vkarpov15/gh-13512 branch June 20, 2023 08:07
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.

None yet

2 participants