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: add forceRepopulate option for populate() to allow avoiding repopulating already populated docs #15044

Merged
merged 2 commits into from
Nov 25, 2024

Conversation

vkarpov15
Copy link
Collaborator

Fix #14979

Summary

It is a little strange that doc.populate('child') will populate 'child' even if 'child' is already populated. This PR adds an option to disable that behavior, either for an individual populate call using doc.populate({ path: 'child', forceRepopulate: false }) or globally with mongoose.set('forceRepopulate', false).

We should consider making forceRepopulate default to false for Mongoose 9.

Examples

@vkarpov15 vkarpov15 added this to the 8.9 milestone Nov 15, 2024
test/model.populate.test.js Outdated Show resolved Hide resolved
Co-authored-by: hasezoey <hasezoey@gmail.com>
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, I also agree it should default to false in v9.0.

One minor addition I would introduce here is a TS type test.

@vkarpov15 vkarpov15 merged commit f9c7c3b into 8.9 Nov 25, 2024
77 checks passed
@hasezoey hasezoey deleted the vkarpov15/gh-14979 branch November 26, 2024 13:59
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.

3 participants