MongoDB 更新文档中$set和$unset的作用

    $set:用来添加或者修改属性

$unset:用来去除属性

例如:

1 /* 使用$unset去除属性price */
2 db.runoob.update({"_id":"5e0da38b6c355e49d8002378"}, {$unset:{"price":0}});
3 
4 /* 使用$set添加或者修改属性price */
5 db.runoob.update({"_id":"5e0da38b6c355e49d8002378"}, {$set:{"price":11.1}});
posted @ 2020-01-02 16:39  松松敲代码  阅读(4225)  评论(2编辑  收藏  举报