$unset
noun
say it: “DOL-er un-SET” /ˈdɑlər ʌnˈsɛt/
A MongoDB update operator that removes a field from a document.
What does $unset do in a MongoDB update?
$unset removes a field from a document altogether, instead of setting it to an empty value. The value written after the field's name doesn't matter; "" is usual.
db.recipes.updateOne({ _id: 4 }, { $unset: { featured: "" } });
db.recipes.findOne({ _id: 4 }).featured;
// undefined
In a sentence
- “At the end of the month, $unset took the featured field off the recipe of the month.”
- “$unset removes the field, where $set with null would leave it there holding null.”
Level: Apprentice · More MongoDB terms at this level
Updated