Now that we had a look at a couple of operators that work nice with numbers or with changing the
values of fields in general,
let's have a look at some operators that work with the field itself.
For that again, let's look into our data and let's say we want to drop the phone value on all persons who
are sporty.
So for this, we can again reach out to our users, update
many users here
and then check if isSporty is true,
that is our condition
and then here is what I want to change,
I want to drop the phone value.
Now one thing you could do is you could set phone to null, if you do that, it updated three elements and
if you now look into your data, you'll see phone is null for everyone except Manuel who is not sporty.
Now
null is not
not that though, drop does mean the field should not be there anymore but it is there, it's just null,
so this is not the perfect solution.
There is a special operator you can use to really get rid of a field though and that is the unset operator,
unset allows you to well unset a field, get rid of a field. Here
the syntax is such that you add a document as a value and then here I want to unset phone and the value
you specify here is totally up to you.
Typically you use an empty string but this will basically be ignored,
the important part is the field name here and that you used unset before. If you now hit enter, three documents
were affected
and if we have a look into our data, there is no phone on Chris,
there is no phone on Anna,
there still is a phone on Manuel but Max's phone number was also dropped.
So this is the unset operator.