In this blog, We’ll walk through CRUD operations (Create, Read, Update, Delete) in MongoDB using a simple example: a student database. We’ll insert student details, query them, update academic information, and even delete records.
To make it more exciting, we’ll run these queries directly on MongoDB Atlas Cluster (cloud-based MongoDB). Along the way, I’ll include screenshots of my MongoDB Atlas dashboard and outputs so you can follow along visually.
Outcome:-
How to insert multiple documents into a collection
How to read and filter records using queries
How to update documents (single & multiple)
How to delete documents based on conditions
How CRUD fits into real-world development
Create (Insert):-
Insert at least 5 student records into the students collection.
We cannot start by inserting 5 student records into our students collection together. We can create each student as separate document.
READ(QUERY)
Find all students with CGPA > 8.
UPDATE
Update the CGPA of a specific student.
Delete:-
Delete one student record by student_id.
Conclusion:-
In this blog, we explored how to perform CRUD operations in MongoDB using a real-world example of a student database. Starting from inserting records, querying based on conditions, updating multiple documents, and finally deleting specific records – we’ve covered the foundation of working with MongoDB.
CRUD operations form the building blocks of every application, whether you’re managing users in a website, products in an e-commerce app, or students in a college system.
Top comments (0)