🗒 Cheat Sheet← Lesson
BitWithBite
Full-Stack Worksheet

🍃 MongoDB & Mongoose

Chapter: Node.js & Express — Backend APIs · Level ★★★ · Time: 25 min
SCORE___ / 20
NameClassDate
After this worksheet you can
Define a Mongoose schemaCreate a modelPerform CRUD with MongooseExplain NoSQL vs SQL basics
📚 Quick Recap

🎯 What you'll practice: Schemas, models, and Mongoose CRUD operations against MongoDB.

🧠 Section A · Concept Check ● BEGINNER 4 × 1 = 4

1MongoDB stores data as:
2A Mongoose schema defines:
3A model is created with:
4To find all documents, call:

🧮 Section B · Problem Solving ● INTERMEDIATE 2 + 3×3 = 11

5A required field is marked with { type: String, : true }.
6mongoose.connect() takes a connection .
7Define a schema for a "Task" with a required title (String) and a done (Boolean, default false).
8Write the Mongoose call to create a new Task document.
9Why do the CRUD route bodies barely change when switching from an in-memory array to MongoDB?

🚀 Section C · Challenge ● CHALLENGE 5

10Rewrite the Express GET /api/courses/:id route from Lesson 25 to use Mongoose's findById instead of an in-memory array, including the 404 case.
💭 Reflection — the most useful thing I learned:
A ___/4   B ___/11   C ___/5   Total ___/20 Teacher's Signature Parent's Signature
✂ answer key — fold or cut before handing out

1-B   2-B   3-A   4-B  |  5 = required   6 = string (URI)   7 = const taskSchema=new mongoose.Schema({title:{type:String,required:true},done:{type:Boolean,default:false}});   8 = await Task.create({title:'Buy milk'});   9 = Mongoose's model methods (find, create, findByIdAndUpdate, findByIdAndDelete) mirror the same find/push/filter operations used on an array, just backed by a real database — the route logic and response shape stay the same  |  10 = app.get('/api/courses/:id',async(req,res)=>{const c=await Course.findById(req.params.id);if(!c)return res.status(404).json({error:'Not found'});res.json(c);});

📄 Need offline practice?Print this worksheet or open the one-page cheat sheet.
🗒 Cheat Sheet