Model.insertMany with lean: true
is very slow compared to native driver
#14372
Labels
help wanted
help
This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
Milestone
Prerequisites
Mongoose version
6.6.1
Node.js version
16.x
MongoDB version
6.0.1
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
No response
Issue
Hey 👋
I am currently working on a piece of functionality that requires bulk inserting of documents using Mongoose. In the process, I've noticed a considerable performance difference between
Model.collection.insertMany(docs)
method and theModel.insertMany(docs, {lean: true})
method with the{lean: true}
flag. Based on the documentation, I understand that the{lean: true}
option helps to skip the process of hydrating and validating the documents before insertion. I had thought that this would effectively make these two methods roughly equivalent in terms of performance.However, upon performing benchmark tests, I found that
Model.collection.insertMany
is significantly faster thanModel.insertMany({lean: true})
. I am hoping to better understand why this is the case. I am also attaching a script to replicate the issue.Thanks!
The text was updated successfully, but these errors were encountered: