Mastering MongoDB CRUD with a Simple College Student Schema π
Databases are the backbone of modern applications β and MongoDB, with its flexible NoSQL design, has become a developer favorite.
In this blog, Iβll walk you through CRUD (Create, Read, Update, Delete) operations in MongoDB Atlas, using a simple yet relatable example: managing college student records.
π Schema: students Collection
{
"student_id": "S001",
"name": "Santhosh",
"age": 20,
"department": "CSBS",
"year": 2,
"cgpa": 9
}
- Create (Insert)
Insert 5 student records:
db.students.insertMany([
{ "student_id": "S001", "name": "Santhosh", "age": 20, "department": "CSBS", "year": 2, "cgpa": 9 },
{ "student_id": "S002", "name": "Priya", "age": 21, "department": "CSE", "year": 3, "cgpa": 8.7 },
{ "student_id": "S003", "name": "Arjun", "age": 19, "department": "ECE", "year": 1, "cgpa": 7.2 },
{ "student_id": "S004", "name": "Meena", "age": 22, "department": "CSE", "year": 3, "cgpa": 9.1 },
{ "student_id": "S005", "name": "Vikram", "age": 20, "department": "IT", "year": 2, "cgpa": 8.0 }
])
β Inserts multiple documents at once.
- Read (Query)
π Display all records
db.students.find().pretty()
π Find students with CGPA > 8
db.students.find({ cgpa: { $gt: 8 } })
π Find students in Computer Science (CSE)
db.students.find({ department: "CSE" })
- Update
π Update CGPA of a specific student
db.students.updateOne(
{ student_id: "S002" },
{ $set: { cgpa: 9.0 } }
)
π Increase year for all 3rd-year students
db.students.updateMany(
{ year: 3 },
{ $inc: { year: 1 } }
)
- Delete
π Delete one student by student_id
db.students.deleteOne({ student_id: "S003" })
π Delete all students with CGPA < 7.5
db.students.deleteMany({ cgpa: { $lt: 7.5 } })
Deliverables
β MongoDB CRUD queries (insert, find, update, delete)
β Export of final collection (JSON/CSV)
Key Takeaways
CRUD in MongoDB is schema-flexible and beginner-friendly.
Using a real-world example (students) makes learning easier.
These basics set the stage for aggregations, indexing, and scaling.
Tried MongoDB CRUD with your own dataset? Share in the comments!
If you found this useful, drop a and connect with me on LinkedIn.
Top comments (0)