Update multiple matching ids documents with different data in a single call

I have multiple documents each with unique _id but with same studentId like the following

       studentId: "A", 
       assignment: "Passed" 
    }

Now I want to update all matching documents with same studentId with different assignment updates like the following

       studentId: "A", 
       assignment: "Failed"
  ​}

      ​studentId: "A", 
      ​assignment: "Passed"
 ​​}

In a single DB call with an array of assignments statuses passed to it

Is it possible to this without a for loop?

Thanks

You need to look at https://docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/ in order to do what you want to do.

Thanks for the link, I was looking for a single query operation like updateMany but this will also do

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.