Delete a key from a MongoDB document using Mongoose

前端 未结 11 1284
我寻月下人不归
我寻月下人不归 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:08

    I use mongoose and using any of the above functions did me the requirement. The function compiles error free but the field would still remain.

    user.set('key_to_delete', undefined, {strict: false} );
    

    did the trick for me.

提交回复
热议问题