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:

  1. new Query().lean() // true
  2. new Query().lean(true)
  3. new Query().lean(false)
  4. const docs = await Model.find().lean();
  5. 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: