Unit 2: Database Persistence & Cloud DeploymentLesson #3 / 4

Lesson 3: MongoDB Document Database & Mongoose ODM

Er. Manoj Kumar — AuthorEr. Manoj KumarLast Updated: 26 Aug, 2026

1. NoSQL Documents with MongoDB & Mongoose

MongoDB is a document-oriented database that stores records as flexible, JSON-like BSON documents. Mongoose provides a schema-based solution to model application data.

  • Schema Definition: Enforces required types, defaults, and validations.
  • Model Instance: Interacts with the database collection for CRUD operations (User.find(), User.create()).
  • Code Example
    import mongoose from 'mongoose';
    const StudentSchema = new mongoose.Schema({
    name: { type: String, required: true },
    email: { type: String, required: true, unique: true },
    enrolledCourse: { type: String, default: 'Full Stack Web Dev' },
    completedLessons: { type: [Number], default: [] },
    createdAt: { type: Date, default: Date.now }
    });
    export const Student = mongoose.model('Student', StudentSchema);

    Interactive Knowledge Check

    Test your understanding of Lesson #3 concepts

    In MongoDB, what is a document collection equivalent to in relational SQL databases?