DEV Community

HARINI SRI K A 24CB016
HARINI SRI K A 24CB016

Posted on

Getting Hands-on with MongoDB: CRUD Operations for College Students

Working with databases is an essential skill for any developer. Recently, I explored MongoDB, a popular NoSQL database, by performing basic CRUD (Create, Read, Update, Delete) operations using a simple students collection. Here’s a walkthrough of my learning journey.

  1. The Students Collection Schema
    {
    "student_id": "S001",
    "name": "Santhosh",
    "age": 20,
    "department": "CSBS",
    "year": 2,
    "cgpa": 9
    }
    db.students.insertMany([
    { "student_id": "S001", "name": "Santhosh", "age": 20, "department": "CSBS", "year": 2, "cgpa": 9 },
    { "student_id": "S002", "name": "Ananya", "age": 19, "department": "CSE", "year": 1, "cgpa": 8.5 },
    { "student_id": "S003", "name": "Rohit", "age": 21, "department": "ECE", "year": 3, "cgpa": 7.8 },
    { "student_id": "S004", "name": "Priya", "age": 22, "department": "CSE", "year": 3, "cgpa": 9.2 },
    { "student_id": "S005", "name": "Kiran", "age": 20, "department": "ME", "year": 2, "cgpa": 6.9 }
    ]);

  2. Reading (Querying) Data
    db.students.find().pretty();
    db.students.find({ "cgpa": { $gt: 8 } }).pretty();
    db.students.find({ "department": "CSE" }).pretty();

  3. Updating Data
    db.students.updateOne(
    { "student_id": "S002" },
    { $set: { "cgpa": 9.0 } }
    );

db.students.updateMany(
{ "year": 3 },
{ $inc: { "year": 1 } }
);

  1. Deleting Data
    db.students.deleteOne({ "student_id": "S005" });
    db.students.deleteMany({ "cgpa": { $lt: 7.5 } });

  2. Exporting the Collection
    MongoDB Atlas makes exporting simple:

Go to Collections → students → Export Collection.

Choose JSON or CSV format to save your data.


Conclusion

Working with MongoDB through this hands-on CRUD exercise was a great learning experience. I learned how to create, read, update, and delete documents in a NoSQL database, and how MongoDB’s flexible schema makes managing real-world data simple and efficient. Using MongoDB Atlas also made it easy to visualize the data and perform operations in a cloud environment.

This exercise strengthened my understanding of database concepts and gave me confidence to work with NoSQL databases in future projects.
thank you sir@santhoshnc !!!!

Top comments (0)