Mongoose is an object modeling layer for MongoDB built for async Node.js code. It adds schemas, validation, and query helpers on top of the official MongoDB driver.
Overview
Mongoose gives Node.js applications a structured way to define MongoDB documents through schemas instead of ad hoc objects. Developers connect with mongoose.connect or separate connections, define models, and then create, query, update, and delete records with familiar methods such as find, findOne, and save.
Schemas declare field types, defaults, getters, setters, indexes, validators, middleware, statics, methods, and plugins. Embedded subdocuments reuse the same features as top-level models, so nested data can be added or removed like ordinary JavaScript objects while still passing through validation and hooks.
The package sits on the official MongoDB Node.js driver and buffers commands until a database connection is ready, which lets applications register models and issue queries before connect completes. Direct access to the underlying collection is possible but bypasses most Mongoose behaviors except command buffering.
Alpha Deno support is available alongside Node.js installs through common JavaScript package managers. A separate Mongoose Studio GUI targets teams that already use Mongoose for in-browser document editing, though that companion is distinct from the core ODM library itself.
Key features
- Schema-driven document models
- Built-in validation and casting
- Query and update helpers
- Middleware and lifecycle hooks
- Embedded document support
- Indexes and defaults
- Plugin ecosystem
- MongoDB driver integration
Use cases
- Node.js apps using MongoDB
- Structured document validation
- Application data modeling layers
- Nested subdocument hierarchies