DEV Community

Cover image for MongoDB
TERERA FAITH TANAKA 24CB070
TERERA FAITH TANAKA 24CB070

Posted on

MongoDB

Introduction

In this blog, we will gain practical experience performing CRUD (Create, Read, Update, Delete) operations in MongoDB. We will use a simple college student schema in a students collection and run queries on MongoDB Atlas.
Schema (Collection: students)
Each student document should follow the structure below:
{
"student_id": "S001",
"name": "Santhosh",
"age": 20,
"department": "CSBS",
"year": 2,
"cgpa": 9
}

Create (Insert)
CREATE A DATABASE CALLED COLLEGE_STUDENTS AND A COLLECTION CALLED STUDENTS


Insert at least 5 student records into the students collection.

Read (Query)
Display all student records.


Find all students with CGPA > 8.

Find students belonging to the Computer Science department.

Update

Update the CGPA of a specific student.
modify cgpa of Faith to 8.3

Increase the year of study for all 3rd year students by 1
before


after

Delete

Delete one student record by student_id.


*Delete all students having CGPA < 7.5.
*

Conclusion

Mastering CRUD operations in MongoDB is fundamental for building efficient and scalable applications that rely on flexible, document-based data storage. By understanding how to Create, Read, Update, and Delete data effectively, developers can leverage MongoDB’s powerful querying capabilities and schema flexibility to manage data in real-time applications with ease. Whether you’re building a small project or a complex system, a solid grasp of these operations ensures that your data management is both robust and performant.Thanks to @santhoshnc for the guidance.

Top comments (0)