π Objective
In this post, weβll explore how to perform CRUD (Create, Read, Update, Delete) operations in MongoDB using a simple College Student schema.
This activity helped me understand how MongoDB stores data in collections and how to interact with it using queries.
π§© Schema β Collection: students
Each document in the collection follows this structure:
{
"student_id": "S001",
"name": "Santhosh",
"age": 20,
"department": "CSBS",
"year": 2,
"cgpa": 9
}
βοΈ 1οΈβ£ Create (Insert)
Insert multiple student records:
db.students.insertMany([
{ "student_id": "S001", "name": "Santhosh", "age": 20, "department": "CSBS", "year": 2, "cgpa": 9 },
{ "student_id": "S002", "name": "Deepa", "age": 19, "department": "CSE", "year": 1, "cgpa": 8.7 },
{ "student_id": "S003", "name": "Meena", "age": 21, "department": "IT", "year": 3, "cgpa": 7.9 },
{ "student_id": "S004", "name": "Kavin", "age": 22, "department": "CSBS", "year": 3, "cgpa": 8.4 },
{ "student_id": "S005", "name": "Arun", "age": 20, "department": "EEE", "year": 2, "cgpa": 6.9 }
])
π 2οΈβ£ Read (Query)
π Display all student records:
db.students.find()
π Find students with CGPA > 8:
db.students.find({ cgpa: { $gt: 8 } })
π Find students belonging to the Computer Science
db.students.find({ department: { $regex: "CS", $options: "i" } })
βοΈ 3οΈβ£ Update
π Update the CGPA of a specific student:
db.students.updateOne({ student_id: "S002" }, { $set: { cgpa: 9.1 } })
π Increase the year of study for all 3rd year students by 1:
db.students.updateMany({ year: 3 }, { $inc: { year: 1 } })
ποΈ 4οΈβ£ Delete
π Delete one student record by student_id:
db.students.deleteOne({ student_id: "S005" })
π Delete all students having CGPA < 7.5:
db.students.deleteMany({ cgpa: { $lt: 7.5 } })
π€ Deliverables
β
MongoDB queries (insert, find, update, delete)
β
Screenshots from MongoDB Atlas showing query outputs
β
Export of the final students collection in JSON/CSV format
π‘ Summary
Through this exercise, I learned how MongoDB handles data in a document-based structure and how CRUD operations can be done easily using built-in commands.
π Special Thanks
A special thanks to Santhosh NC Sir for his guidance and continuous support in this DBMS learning journey.
Top comments (0)