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 · 3 comments · Fixed by #14723 or #14943
Closed
2 tasks done

Unreported breaking change - insertMany with lean option #14698

nadavhalfon opened this issue Jun 30, 2024 · 3 comments · Fixed by #14723 or #14943
Labels
new feature This change adds new functionality, like a new method or class
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

@ayoubkhial
Copy link

ayoubkhial commented Sep 27, 2024

This behavior is still present in version 8.7.0. It's not just the default values but also timestamps.

@vkarpov15 vkarpov15 reopened this Oct 6, 2024
@vkarpov15 vkarpov15 modified the milestones: 8.4.5, 8.6.5 Oct 6, 2024
@vkarpov15 vkarpov15 removed the docs This issue is due to a mistake or omission in the mongoosejs.com documentation label Oct 6, 2024
@vkarpov15 vkarpov15 modified the milestones: 8.7.1, 8.7.2, 8.8 Oct 8, 2024
@vkarpov15 vkarpov15 added the new feature This change adds new functionality, like a new method or class label Oct 8, 2024
vkarpov15 added a commit that referenced this issue Oct 8, 2024
…tamps, including subdocuments, to a given POJO

Fix #14698
vkarpov15 added a commit that referenced this issue Oct 13, 2024
feat(model): add applyTimestamps() function to apply all schema timestamps, including subdocuments, to a given POJO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature This change adds new functionality, like a new method or class
Projects
None yet
5 participants