In MongoDB, the update modifier unset works as follows:
Consider a Mongo DB Database db with a collection users. Users contain a Document, of the f
The short answer is because {"relationships.terminated"}
is not a valid json/bson object. A JSON object is composed of a key and a value, and {"relationships.terminated"}
only has a key (or value, depends on how you look it).
Affortunately to unset a field in Mongo you do not need to set the actual value of the field you want to remove. You can use any value (1 is commonly used in Mongo docs) no matter the actual value of relationships.terminated
:
db.users.update({"username":"joe"},{"$unset":{"relationships.terminated" : 1}});