I can’t see the difference between using it:
update({"name" : "nick"}, {"$set" : {"age" : 50}})
and not using it;
update({"name" : "nick"}, {"age" : 50})
from the example in documentation. It’s not clear to me.
Thanks for the comment but if I use {"$set" : {"array_field" : [{'f' : 'v'}] }} it adds {'f' : 'v'} to the array instead of replacing the array with [{'f' : 'v'}], so why doesn’t $set replace the array with the new one?
update({"name" : "nick"}, {"age" : 50})replaces the complete object with only{"age" : 50}.Running
find({"name" : "nick" })after running the above update would return no document found error.Using $set would allow to update only the “age” param of the original object.
Karl Seguin’s Little Mongodb Book has a very good explanation about the difference between replace and set.