Mongoose lean() vs hydrated documents: choose read performance or full document features
Decide between Mongoose lean() and hydrated documents for read-heavy Node.js APIs, with trade-offs, a compact comparison, and a verification script.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
Decide between Mongoose lean() and hydrated documents for read-heavy Node.js APIs, with trade-offs, a compact comparison, and a verification script.
Mongoose virtuals let you define computed properties like fullName without storing them in MongoDB, but they are hidden from JSON output unless you enable schema serialization.
Mongoose hooks failing to run, duplicating, or hanging usually stem from incorrect registration timing, schema reuse, or improper async handling (missing await/return). Use this guide to diagnose and fix the issue.
Use Mongoose skip() and limit() with countDocuments() for stable, index-aware page-based pagination in Node.js.
Mongoose middleware gives a single enforcement point for data integrity across all entry points, but only as a local trust boundary not an authorization layer. Maps hook types to jobs, failure modes, and a verification script.
Learn how Mongoose pre('save') middleware centralizes field normalization for regular saves, why bulk operations bypass it, and how to handle the gap safely.
Learn how to add a Mongoose pre‑save hook that hashes passwords with bcrypt only when they are changed, keeping plaintext credentials out of MongoDB.
Stop repeating data sanitization logic in your controllers. Learn how to use Mongoose pre and post hooks to centralize password hashing and side effects.
Learn how to centralize validation and side‑effects in Mongoose using schema pre‑ and post‑save hooks, with a concrete password‑hashing example and guidance on testing and performance trade‑offs.