1.$inc: 对数字字段内容进行修改
db.getCollection('student').update(
{'age':19},
{$inc:{'score':-20}}
)
2.$set :对字段内容进行修改
3.$unset :对字段内容进行删除
db.getCollection('student').update(
{'name':'eggsy'},
{$unset:{'score':1,'age':1}}
)
4.$push : 追加内容,数组
db.getCollection('student').update(
{'name':'eggsy'},
{$push:{'course':'数学'}}
)
5.$pushAll : 一次追加多个内容到数组中
db.getCollection('student').update(
{'name':'eggsy'},
{$pushAll:{'course':['英语','马列']}}
)
6.$addToSet : 向数组里面增加一个新的内容,只有当内容不存在的时候,才会增加
db.getCollection('student').update(
{'name':'eggsy'},
{$addToSet:{'course':'英语'}}
)
7.$pull : 删除数组中指定内容
db.getCollection('student').update(
{'name':'eggsy'},
{$pull:{'course':'英语'}}
)
8.$pullAll :一次性删除数组多个内容
db.getCollection('student').update(
{'name':'eggsy'},
{$pullAll :{'course':['英语','语文']}}
)