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

猜你喜欢

转载自www.cnblogs.com/thaipine/p/12133796.html