Advertisement
shopnilSS

Update multiple Doc in a single request

Feb 16th, 2022
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let input = [
  2.     {'name':'Ajay','marks':20},
  3.     {'name':'Pinku','marks':12},
  4.     {'name':'Vinod','marks':50},
  5.     {'name':'Rahul','marks':80}
  6. ];
  7. let operations = input.map(function(student){
  8.    return {updateOne:{filter:{name:student.name},update:{$set:{marks:student.marks}}
  9. };
  10. db.collection.bulkWrite(operations);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement