Suppose I will find a product whose ID is hundred. And then I want to update few properties of the product. So we would say DB dot products dot update, and the query is underscore ID is 100. And then the updating document happens to be a new one, probably I can say, name equals to test product. And then I will say, unit price happens to be let's say 100.0. And a description of the same thing happens to be test description.
For now, I think these properties should be good enough. Let's save this and then run the same thing. To run that as a Mongo less than extend dot j s, press enter, and it comes back with a result. The result says number of matched documents is Zero upsetted zero modified zero. The reason is very simple. We don't have the document with an ID of 100.
So let's go check it out. I go to the Mongo test dB, and say, db dot products dot find underscore ID is 100. And you can see that it came back with nothing. We can also ask MongoDB to insert a new document in case if the update failed. Now this concept is called upsetting. So we come back to this particular code.
And then we specify here a third parameter where we say absurd is true. We say that search for this document, if it is found, you need to change this as the new document. If it's not found, you need to add that update or insert. So one more thing is that if the product already existed with multiple fields on The fields will be lost, and only these fields will be the new fields. So in order to avoid that I can say, dollar set. And then we can specify all these properties.
So let's execute the script and check the result. And this time it is number of matched documents is zero, number of absurd document is one modified is zero, the ID generated happens to be 100. And that's because we supplied that, let's go and verify the same thing. Type Mongo, test two DVDs, and then I'd say DB dot products dot find one with an ID of 100. And the VC that isn't