What does Mongoose lean() do?
Mongoose's lean() option causes queries to return plain JavaScript objects instead of fully hydrated Mongoose documents. This can reduce overhead and improve read performance when document methods, getters, setters, virtuals, and other Mongoose document behavior are not required. The exact behavior depends on the query and any plugins or additional options being used.
Key Takeaways
- lean() can reduce Mongoose document overhead.
- It is useful for read-heavy operations that do not need document methods.
- Lean results do not behave exactly like hydrated Mongoose documents.
Knowledge Check
What does Mongoose lean() generally return?