Deleting a key/value from existing MongoDB entry

前端 未结 3 1717
情话喂你
情话喂你 2020-12-08 04:42

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

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-08 05:04

    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} })
    

提交回复
热议问题