MongoDB & Mongoose
Document modeling, aggregation, indexes, and consistency.
Schema vs model vs document in Mongoose?
A Mongoose schema defines document fields and behavior, and compiling it creates a model used for collection operations. A document is one hydrated record returned or created through that model. Hydration supplies methods and change tracking, which are useful for edits but add work compared with plain objects.
Populate vs lean: what should I remember?
populate resolves references so related records are available in a query result. lean skips creating full Mongoose document instances and returns plain JavaScript objects. One controls related-data retrieval and the other controls result hydration, so they solve different performance concerns.
What are hooks, virtuals, instance methods and static methods?
Hooks run around selected document or query operations, virtuals compute values that are not normally stored, and methods attach reusable behavior to documents or models. These features keep related logic near the data model. However, each feature has a defined execution context and does not apply to every write path automatically.
Is Mongoose validation enough to protect data?
Mongoose validation checks values against rules declared in a schema before supported operations complete. It improves input quality but cannot enforce every cross-document or concurrent business rule. Database constraints, conditional updates and authorization checks remain necessary because other writers or races may bypass application checks.
Difficulty is an editorial estimate. Completion means you chose to mark a question as understood.