DAY 10 OF MY BACKEND JOURNEY
Today, I mastered CRUD Operations with Mongoose.
The core pattern that powers every REST API by exposing create, read, update, and delete operations over HTTP.
Learning with
@Nannoyapp
● I learned that CRUD reduces every backend feature user accounts, blog posts, orders to four fundamental operations that map directly to HTTP methods: POST, GET, PUT, and DELETE.
● I discovered that Product.create() is shorthand for saving new documents, Product.find() retrieves all documents, and Product.findById() retrieves one specific document by ID.
● I understood the importance of always checking if (!product) before using query results, because Mongoose returns null instead of throwing an error when no document is found, requiring explicit 404 handling.
● I learned that findByIdAndUpdate() requires { new: true } to return the updated document and runValidators: true to enforce schema validation on updates, preventing invalid data from bypassing rules.
● I discovered the complete CRUD-to-HTTP mapping: POST creates (201), GET reads (200), PUT updates (200), and DELETE removes (200), with proper status codes signaling operation success to clients.
● I understood that testing each CRUD operation in order POST first to create data, then GET, PUT, DELETE builds confidence and confirms data actually persists in MongoDB.
● I troubleshot MongoDB connection issues with VPN and learned that network restrictions require proper configuration before the API can communicate with the database.
● I now know that mastering this five-handler pattern makes building any resource API repeatable and scalable swap the model name and you have a complete REST API in under 50 lines of code.