I need to delete a certain key and value from every entry in a particular collection. I\'ve looked into remove and that seems to be for only entire entries. Looking at updat
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" } )]
Also think about upsert()
that will insert your row as a new document if _id
does not exist or update the existing document if any.
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} })