Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting a key/value from existing MongoDB entry

Tags:

mongodb

People also ask

How do I remove an object from an object in MongoDB?

To remove only a single object, provide it with another field to uniquely identify it. If you only want to remove the object that contains the title field from the array but wants to keep the object that contains the array, then please use the $pull operator. This answer will be of help.


Try $unset in a call to update().

Like this:

db.collection_name.update({ _id: 1234 }, { $unset : { description : 1} })

And, as vikneshwar commented, if you want to remove one field from all (or multiple) documents you can use updateMany() like this:

db.collection_name.updateMany({}, { $unset : { description : 1} })

To reference a package and remove various "keys", try this

db['name1.name2.name3.Properties'].remove([ { "key" : "name_key1" }, { "key" : "name_key2" }, { "key" : "name_key3" } )]