20MIA1126 Lab2
20MIA1126 Lab2
db.MIA1126.insertMany([
"name": "Chenchu",
"registerNumber": "1126",
"address":"Thazambur chennai"
},
"name": "Aravind",
"registerNumber": "1127",
},
"name": "Pavani",
"registerNumber": "1128",
]);
2.Update the student name for the given registration number
db.MIA1126.updateOne(
{ "registerNumber": "1127" },
{ $set: { "name": "Rahul" } }
);
Update the address for the given name and show the upsert option with explanation
db.MIA1126.updateOne(
{ "name": "Rahul" },
{ upsert: true }
);
The upsert option is set to true, which means that if a document with the given
name ("Rahul") doesn't exist, a new document will be inserted with the specified
address (" Guindy Chennai”).
Update the mark of the students for the given name with multi property and provide
suitable explanations
db.MIA1126.updateOne(
{ "name": "Chenchu" },
);
2. Develop a student collection with appropriate complex data types - use array to
store the list of elective subjects and embedded document to store the
subject_name:mark of the subject. Initialize the collection with minimum 3 documents
db.MIA1126.insertMany([
"name": "Chenchu",
"studentId": "1126",
"subjectMarks": {
"Math": 90,
"Science": 85,
"History": 78
},
"name": "Aravind",
"studentId": "1127",
"subjectMarks": {
"Science": 92,
"English": 88,
"Art": 75
},
"name": "rahul",
"studentId": "1128",
"subjectMarks": {
"History": 80,
"Math": 88,
"AI": 95
]);
Update the mark of a particular student for a particular course for a given student id.
db.MIA1126.updateOne(
{ "studentId": "1126" },
{ $set: { "subjectMarks.Science": 95 } }
);
Replace the subject names with “TOC” for a given student name “X”
db.MIA1126.updateOne(
{ "name": "Chenchu" },
);
Replace the subject “X” with “Y” for example (“Science” with “EVS”) for all the
students.
db.MIA1126.updateMany(
{ "electiveSubjects": "History" },
);