-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
perf(model): make insertMany()
lean
option skip hydrating Mongoose docs
#14376
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ok, but i will hold-off on approving until the main 6.x branch does not have failing tests anymore
@hasezoey can you please re-review? This PR has fix for test issues in 6.x. |
@vkarpov15 @hasezoey If not, then LGTM 😁 |
i guess that would be true, but isnt also the documentation already mentions it:
|
Yes, and that's fine in the case of reads, assuming that it's mostly used in the context of reading and then returning in a JSON response. But in the case of writes, very often data is not cast to the proper types, and it would be stored in the database with the wrong type. I feel like people would use that option thinking that it's only a lighter way to "return" the data, unaware of what it means under the hood. 🤔 |
I can see @AbdelrahmanHafez 's point, but I'm not sure I fully agree. Even before this change, |
Yeah, I am not referring to this change as the concern, it's generally having the Now that I think about it, a warning would be enough, especially that we have |
docs(model): add extra note about `lean` option for `insertMany()` skipping casting
Fix #14372
Summary
Initial implementation of
lean
forinsertMany
in #8507 madelean
just skip validation, not hydrating docs, which makesinsertMany
withlean
still significantly slower. I'm inclined to change it so thatinsertMany
withlean
also skips hydrating Mongoose docs, because the namelean
implies that we skip all hydration and other Mongoose-specific stuff similar to query lean.Examples