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

Unreported breaking change - insertMany with lean option #14698

Closed
2 tasks done
nadavhalfon opened this issue Jun 30, 2024 · 2 comments · Fixed by #14723
Closed
2 tasks done

Unreported breaking change - insertMany with lean option #14698

nadavhalfon opened this issue Jun 30, 2024 · 2 comments · Fixed by #14723
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation
Milestone

Comments

@nadavhalfon
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

When this issue was raised: #14372
The fix was to skip hydration in "insertMany" - this causes a bug where insertMany suddenly does't take care for "defaults"
I think it should be mention somewhere, just wanted to point it out 🙏

Thank you very much for your work !

@IslandRhythms IslandRhythms added discussion If you have any thoughts or comments on this issue, please share them! docs This issue is due to a mistake or omission in the mongoosejs.com documentation and removed discussion If you have any thoughts or comments on this issue, please share them! labels Jul 2, 2024
@vkarpov15
Copy link
Collaborator

That's a good point, we will add this to our docs. As a workaround, you can use Model.applyDefaults() to apply the defaults to your lean objects before saving as follows.

await MyModel.insertMany(docs.map(doc => MyModel.applyDefaults(doc)), { lean: true })

@vkarpov15 vkarpov15 added this to the 8.4.6 milestone Jul 3, 2024
vkarpov15 added a commit that referenced this issue Jul 4, 2024
docs(model): note that `insertMany()` with `lean` skips applying defaults
@vkarpov15 vkarpov15 modified the milestones: 8.4.6, 8.4.5 Jul 4, 2024
@7freaks-otte
Copy link

Note: This seems to have appeared in the 7.x branch as well - presumably with 7.6.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants