Let's say we want to increment the price of all the products of fresher brand. So first, let's find out what are those products. So we get into the Mongo shell, test database. And then I'll say DB dot, products dot find. And I'll get the condition as brand is fresher. And we can also say pretty, so that we can see the results properly.
So there are many of them. Let's see the last few of them were the product price happens to be 2935 and 39. And we want to check if that increases the product price for all of this. So let's write the query for the same thing. So we said dv dot products dot update. And the criteria happens to be brand equals to fresher.
And then to increment the price we can say dollar Learn IMC for increment, we say unit price and the amount being incremented. Let's say we want to increment this by five rupees. So, it says here that find all the products with this brand fresh Oh, and then increment the unit price by five. So if it is 30, it should become 3535 becomes 40 and so on. So, let's see if this works. Save this and execute this.
When I execute, it says number of documents matched one. Absurd is zero modified is one but we saw there are many, many documents matching that condition. But there was only one update to place. Now this is because by default MongoDB updates the very first document that it finds now since in this case it was quite arbitrary. We don't get the desired result. You can Go and verify that also.
Alternately, we go here and then specify a third option where we earlier give absurd this time we don't want to really absurd but we can say here, multi AZ true. Now by default multi has been set as false. So we save this, we run the same thing again and you can see it this time it says matched documents or 56. Modified documents are 56. So we can also go to the Mongo shell, and check DB dot products dot find. And we say brand threshold.
We'll also say pretty. So if you remember the last few outputs, we had 35. For this, we now have 40. We had 39, and it is 44. And we had 29. That's changed to 34.
So this way, we can update multiple documents as well.