You are on page 1of 3

CSE3086 20MIA1002

LAB ASSIGNMENT – 3

Q1) Update operations with ArrayFilter

db. Lab3.insertMany ([{marks: [73,64,48], subject: ['maths', 'iv',


'eda'], dept: 'MIA', reg:1001}, [marks: [37,89], subject: ['dl',
'ml'],dept: 'AIML', reg:1002},{marks: [78,82], subject: ['ml',
'dl'], dept: 'AIML", reg:1003}

• Update the subject name ‘X’ as ‘Y’ for M.Tech AI ML students

db.lab3.update({dept:'AIML'},{$set:{"subject.$[ele]":'ai'}},{multi:t
rue, arrayFilters:[{"ele":"dl"}]})
• Update the marks of students which are less than 50 as 50 for the given
student registration number.
db.lab3.update({reg:1002},{$set:{"marks.$[ele]":50}},{multi:true,
arrayFilters:[{"ele":{$lt:50}}]})

• Write about the purpose of ArrayFilters option in Update command

Used to update the values of an element across different indexes in the array.

• Create a .json file with 3 students details and name the file as your
registration_number.json. Then move the file to new collection in
mongodb through monogo import command. Make sure that
mongoimport command should be executed in normal command prompt
not inside the mongo shell.

You might also like