db.students.insertMany([
  {
    "student_id": "S001",
    "name": "Santhosh",
    "age": 20,
    "department": "CSBS",
    "year": 2,
    "cgpa": 9
  },
  {
    "student_id": "S002",
    "name": "Aarav",
    "age": 21,
    "department": "CSE",
    "year": 3,
    "cgpa": 8.5
  },
  {
    "student_id": "S003",
    "name": "Meera",
    "age": 19,
    "department": "ECE",
    "year": 1,
    "cgpa": 7.2
  },
  {
    "student_id": "S004",
    "name": "Divya",
    "age": 22,
    "department": "CSE",
    "year": 3,
    "cgpa": 9.1
  },
  {
    "student_id": "S005",
    "name": "Rohan",
    "age": 20,
    "department": "MECH",
    "year": 2,
    "cgpa": 6.8
  }
])
  Read (Query)
Display all student records
js
db.students.find()
Find all students with CGPA > 8
js
db.students.find({ cgpa: { $gt: 8 } })
Find students belonging to the Computer Science department
js
db.students.find({ department: "CSE" })
  Update
Update the CGPA of a specific student (e.g., student_id: "S003")
js
db.students.updateOne(
  { student_id: "S003" },
  { $set: { cgpa: 7.8 } }
)
Increase the year of study for all 3rd year students by 1
js
db.students.updateMany(
  { year: 3 },
  { $inc: { year: 1 } }
)
  Delete
Delete one student record by student_id (e.g., "S005")
js
db.students.deleteOne({ student_id: "S005" })
Delete all students having CGPA < 7.5
js
db.students.deleteMany({ cgpa: { $lt: 7.5 } })
For further actions, you may consider blocking this person and/or reporting abuse
 



 
    
Top comments (0)