Delete a key from a MongoDB document using Mongoose

前端 未结 11 1289
我寻月下人不归
我寻月下人不归 2020-11-27 04:38

I\'m using the Mongoose Library for accessing MongoDB with node.js

Is there a way to remove a key from a document? i.e. not just set the value to n

11条回答
  •  南笙
    南笙 (楼主)
    2020-11-27 05:01

    if you want to remove a key from collection try this method. this worked for me

     db.getCollection('myDatabaseTestCollectionName').update({"FieldToDelete": {$exists: true}}, {$unset:{"FieldToDelete":1}}, false, true);
    

提交回复
热议问题