Build HTTP APIs with routing, middleware, validation, controllers, and error handling.
Lessons
Model documents and query MongoDB from Express routes.
MongoDB with Mongoose is easiest to learn by reading the example, changing it, and observing the result.
// npm install mongoose
import mongoose from 'mongoose';
await mongoose.connect(process.env.MONGODB_URI);
const Lesson = mongoose.model('Lesson', new mongoose.Schema({
slug: { type: String, unique: true },
title: String,
minutes: Number
}));
const lesson = await Lesson.create({ slug: 'express-routing', title: 'Routing', minutes: 30 });
console.log(lesson.id);Practice the MongoDB with Mongoose example in a small scratch file, then explain what changed and why.