Now we saw inc for increment or actually also as you saw, decrementing a field. Now other useful operators
are min, max and mul,
now let me quickly show you how these work.
Let's again look into our data and let's say now for Chris we want to set the age to 35 but only
if the existing age is higher than that.
Now obviously we see that this is the case but this is another common thing,
a scenario you might encounter, that you want to set some field to a certain value but only if it currently
is higher and not if it is lower,
so let me show you how this would work. For this, we'll simply filter by name again, I'll use update one and
I'll filter for name equal to Chris.
Now here we can use the $min operator and then specify the field name, age and set it to 35.
If I now hit enter, you see one document was found and one document was edited and indeed, if I look into
my data, we see that Chris is now 35.
Now let me show you a case where this will fail or where this will not change anything to be precise.
If I now set min age for Chris to 38,
keep in mind he is currently 35, if I hit enter here,
you see it matched but it didn't change anything,
it didn't throw an error either,
it just did not change anything
and you see the age is still at 35 because min only changes the value if the new value is lower
than the existing value
and the same also exists for max unsurprisingly.
So if I repeat this but I replace min with max and I set it to 32 for a start,
keep in mind Chris is still 35,
so this value is actually lower, then max will not do anything,
if I set it to a higher value like 38, it will update Chris because unlike min, max simply does update
if the old value is lower than the new value.
Now last but not least, we also got mul, multiply.
Let's quickly look into the data to confirm that Chris is 38,
yes he is
and with that confirmed,
let me show you the last operator.
Let me add mul or use mul like this
and now this will multiply the age by a number we specify,
so let's say Chris got 10% older, so we could multiply age by 1.1.
If I hit enter, that succeeded and if we have a look at all the data, we see Chris was 38, now he
is 41.8
and this is something which will become clearer once we are in the numeric data module where I will
talk about this missing precision here
but basically he got 3.8 years older which happens to be 10% of 38, his old age.
So this is the mul, the multiply operator.