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 flattenObjectIds option to toObject() and toJSON() #13383

Merged
merged 1 commit into from May 8, 2023

Conversation

vkarpov15
Copy link
Collaborator

Fix #13341
Re: #2790

Summary

See discussion from #13341. TLDR; toObject({ flattenObjectIds: true }) will return an object with all ObjectIds converted to strings. There are a couple of ways to do this with Mongoose, but the other alternatives aren't sufficiently fine-grained: JSON.parse(JSON.stringify(doc)) will JSON-ify everything, mongoose.ObjectId.set('transform', v => v.toString()) will apply this behavior to every toObject() call, etc.

Examples

@vkarpov15 vkarpov15 added this to the 7.2.0 milestone May 6, 2023
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

@vkarpov15 vkarpov15 merged commit 3da4992 into 7.2 May 8, 2023
34 of 37 checks passed
@hasezoey hasezoey deleted the vkarpov15/gh-13341 branch May 9, 2023 09:04
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