db.collection.update({条件},{$unset:{字段名:""}})
例如:
db.user.update({name:"zhangsan"},{$unset:{"hobby":"","height":""}});
设置为null:
db.user.update({name:"zhangsan"},{$set:{"hobby":null,"height":null}});
他们分别在表中显示为

本文介绍如何使用MongoDB的update方法来修改文档中的特定字段,包括将字段设为空字符串或null值的方法。
db.collection.update({条件},{$unset:{字段名:""}})
例如:
db.user.update({name:"zhangsan"},{$unset:{"hobby":"","height":""}});
设置为null:
db.user.update({name:"zhangsan"},{$set:{"hobby":null,"height":null}});
他们分别在表中显示为

378
1万+

被折叠的 条评论
为什么被折叠?