Reputation: 335
I have a collection with single DOC which I use as "source of truth" and want to be able to remove & add values to it:
{
"_id" : ObjectId("61012ada8d2ccb252be87551"),
"language" : "english",
"gui-ipv6" : "disable",
"gui-certificates" : "enable",
"gui-custom-language" : "disable",
"gui-display-hostname" : "disable",
"admin-https-ssl-versions" : "tlsv1-1 tlsv1-2 tlsv1-3",
}
I want to be able to delete a line, say language for example. Whenever I try to do this, it removes entire DOC since my query matches entire DOC e.g:
db.my_collection.remove({'language': {$exists:true}})
Any ideas on how to solve this?
Thank you.
Upvotes: 0
Views: 366
Reputation: 144
Use operator unset for delete field https://docs.mongodb.com/manual/reference/operator/update/unset/
db.my_collection.update(
{},
{ $unset: { language: "" },
false, true }
)
Upvotes: 1