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(document): add schemaFieldsOnly option to toObject() and toJSON() #15259

Merged
merged 5 commits into from
Feb 17, 2025

Conversation

vkarpov15
Copy link
Collaborator

Fix #15218

Summary

toObject() and toJSON() currently return an object with all fields from the document in the database, which may include fields that aren't in the schema. To work around that, we added a schemaFieldsOnly option to toObject() and toJSON(), which will loop over schema paths when getting values vs just cloning the entirety of _doc.

Examples

@vkarpov15 vkarpov15 added this to the 8.11 milestone Feb 13, 2025
Copy link
Collaborator

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

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

LGTM, some minor style suggestions.

@vkarpov15 vkarpov15 merged commit 48f9574 into 8.11 Feb 17, 2025
77 checks passed
@vkarpov15 vkarpov15 deleted the vkarpov15/gh-15218-2 branch February 17, 2025 15:33
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.

2 participants