Update multiple documents with different values

How to update multiple documents based on “_id” to change field value which contains different values.

Eg.

Id (1)
{
   Item: pen1
   price: 10
}

id(2)
{
   Item: pen2
   price: 15
}

requires is to update price value based on Id…
Like update Id(1) price->20
Id(2) price->35

please let me know…for updating this in 1000+ records…

Hey @shubham_udata

I think your best bet is to use bulkWrite and give it the array of updates you are making on the collection.
I have linked the docs for this below.

You would create an array of all the updates you want done to the collection. Each item of the bulkWrite array can perform insert, update, delete and replace operations.
It would be up to you to determine which action is appropriate and how to update the record.

4 Likes