Now there's one more command I want to show you, for that let's cycle through the past commands to the
command where I pushed a single hobby to Maria
and let me change this to hiking.
Now here I push a single object, the command I'll show you will not work with each with that array
but if you push one object which I can do with push of course, you can also use addToSet instead.
If I hit enter, you see one document was modified
and if I find them all, you see hiking is there.
The question is what is the difference to push? That should become clearer once I try the exact same
command again. Previously with push,
we were able to push duplicate values.
Now you see modified count is 0,
we get no error but you see nothing was changed
and indeed if we look into the data, there is still only one hiking hobby.
The difference is that addToSet adds unique values only,
so if you try to add a value that's already part of the array, it will not be added again
and that can of course also be helpful in some situations.