Node.js › Databases & ORMs (MongoDB/Mongoose, SQL/Sequelize)

What is Mongoose, and what does it add on top of the raw MongoDB Node.js driver?

Beginner

Answer

Mongoose is an Object Document Mapper (ODM) for MongoDB, adding schema definition and validation (MongoDB itself is schemaless by default), typed model classes with instance and static methods, middleware/hooks (like running logic before or after a save), and built-in support for defining relationships between documents -- all on top of the lower-level, more manual raw MongoDB driver, which just gives you direct, unstructured database operations without any of this application-level structure.
const mongoose = require('mongoose');

const userSchema = new mongoose.Schema({
  name: { type: String, required: true },
  email: { type: String, required: true, unique: true },
  age: { type: Number, min: 0 },
});

const User = mongoose.model('User', userSchema);
const user = await User.create({ name: 'Alice', email: 'alice@example.com', age: 30 });
Real-world example A team migrating from the raw MongoDB driver to Mongoose immediately catches several data-quality bugs that had been silently accumulating, since Mongoose's schema validation now rejects documents missing required fields or containing values of the wrong type before they ever reach the database.

Common follow-ups: What's the performance overhead of Mongoose's validation and casting layer compared to using the raw driver directly?;When might a team deliberately choose the raw MongoDB driver over Mongoose despite losing this structure?