Do you want to request a feature or report a bug?
feature
What is the current behavior?
I can't set lean: true
as the default option globally or per schema/model
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
I'd like to set lean: true
as the default behavior globally, and be able to lean: false
on specific calls of findOne
and related methods
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
node: 12.13.0
mongoose: 5.7.7
mongo: 4.2
related to https://github.com/Automattic/mongoose/issues/6266
lean: false is very slow when your collection have a very deep and nested structure
mongoose.plugin(schema => {
schema.pre(['find', 'findOne'], function() {
this.lean();
});
});
That should work for setting all find()
and findOne()
queries to lean. The downside is that right now there's no way to tell whether a query has lean()
set or not without using private state. We'll add that for 5.8.0.
Most helpful comment
That should work for setting all
find()
andfindOne()
queries to lean. The downside is that right now there's no way to tell whether a query haslean()
set or not without using private state. We'll add that for 5.8.0.