Query.prototype.lean()
Parameters
- bool «Boolean|Object» defaults to true
Returns:
- «Query» this
Sets the lean option.
Documents returned from queries with the lean
option enabled are plain javascript objects, not Mongoose Documents. They have no save
method, getters/setters, virtuals, or other Mongoose features.
Example:
new Query().lean() // true
new Query().lean(true)
new Query().lean(false)
const docs = await Model.find().lean();
docs[0] instanceof mongoose.Document; // false
Lean is great for high-performance, read-only cases, especially when combined with cursors.
If you need virtuals, getters/setters, or defaults with lean()
, you need to use a plugin. See:
当前内容版权归 mongoosejs 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 mongoosejs .