CRUD Operations with Mongoose
Implement Create, Read, Update, and Delete operations using Mongoose methods to manage your data.
What is CRUD?
CRUD stands for Create, Read, Update, and Delete. These are the four fundamental operations you perform on data in almost any database application.
Understanding CRUD is key to building interactive applications where users can manage information.
- Create: Adding new data.
- Read: Retrieving existing data.
- Update: Modifying existing data.
- Delete: Removing data.
Our Sample Mongoose Model
Before we perform CRUD operations, we need a Mongoose model. This model defines the structure of our documents in MongoDB.
We'll use a simple Book model for our examples:
const mongoose = require('mongoose');
const bookSchema = new mongoose.Schema({
title: String,
author: String,
year: Number
});
const Book = mongoose.model('Book', bookSchema);This Book model will interact with a books collection in our database.
All lessons in this course
- Connecting Node.js to MongoDB
- Mongoose ODM for Data Modeling
- CRUD Operations with Mongoose
- Querying & Filtering Data with Mongoose