//--- To remove a single field "comments" and Updates all documents that match the specified filter for a collection ---//
xxxxxxxxxx
await db.updateMany({}, [ { $unset: "comments" } ]);
await db.updateMany({_id:'123456789'}, [ { $unset: "comments" } ]);
*update @deprecated use `updateOne` or `updateMany` instead.
mongodb : v6.0.4
xxxxxxxxxx
//--- Delete all attributes which contain id ---//
db.products.update({}, {$unset: {id: true}}, {multi:true} )
//--- Delete all attributes which contain description ---//
db.products.update({}, {$unset: {description: true}}, {multi:true} )
xxxxxxxxxx
=> Use the $unset field update operator to completely remove a field from a document.
{ $unset: { "field_name": "value" } }
=> You can specify multiple fields to remove by separating them with a comma.
{ $unset: { name: "", weight: "" } }