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

fix(model+document): avoid depopulating manually populated doc as getter value #14760

Merged
merged 2 commits into from
Jul 26, 2024

Conversation

vkarpov15
Copy link
Collaborator

Fix #14759

Summary

When depopulating, it looks like Mongoose applies _id getters, which is problematic if you add a default getter to convert all ObjectIds to strings like here: https://thecodebarbarian.com/whats-new-in-mongoose-54-global-schematype-configuration.html#schematype-getters. Fixed by replacing doc._id with doc._doc._id to get the raw id and bypass any getters.

We should backport this to 7.x and 6.x. Same issue impacts those versions.

Examples

@vkarpov15 vkarpov15 added this to the 8.5.2 milestone Jul 23, 2024
lib/document.js Outdated Show resolved Hide resolved
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, minor style suggestion and would like to see the question above resolved

test/model.populate.test.js Outdated Show resolved Hide resolved
@vkarpov15 vkarpov15 merged commit 93684f8 into master Jul 26, 2024
45 checks passed
@hasezoey hasezoey deleted the vkarpov15/gh-14759 branch July 27, 2024 09:36
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.

Manually populated documents get saved as strings instead of ObjectIds in combination with SchemaType getter
4 participants