← Lesson
BitWithBite
Full-Stack · Quick Reference

Lesson 26 — MongoDB & Mongoose Cheat Sheet

Full-Stack
In one line: MongoDB stores flexible JSON-like documents; Mongoose adds schemas and a clean model API for real persistence.

Key Ideas

1MongoDB. NoSQL, document-based database.
2Schema. Defines a document's shape and rules.
3Model. A schema compiled to a usable class.
4mongoose.connect(). Connects using a URI.
5Query methods. find, findById, create, findByIdAndUpdate, findByIdAndDelete.

CRUD

const schema = new mongoose.Schema({ title: {type:String, required:true}, hours: Number }); const Course = mongoose.model('Course', schema); await Course.create({title:'CSS Grid', hours:3}); const all = await Course.find(); await Course.findByIdAndUpdate(id, {hours:4}); await Course.findByIdAndDelete(id);