MongoDB数据修改总结
1.前言
最近在学习MongoDB,数据修改这一部分的内容较多,命令比较繁琐,所以将一些常用的修改命令总结在这篇博客中,方便今后学习的查阅。
2.命令总结
1). insert()
db.collection.insert(x) x就是要更新的对象,只能是单条记录,如:
> db.mytest.find({_id:16}){ "_id" : 16, "x" : [ 2, 2, 3, 1 ] }> db.mytest.update({x:3},{$unset:{"x.$":1}})> db.mytest.find({_id:16}){ "_id" : 16, "x" : [ 2, 2, null, 1 ] }> db.mytest.update({_id:16},{$pull:{x:null}})> db.mytest.find({_id:16}){ "_id" : 16, "x" : [ 2, 2, 1 ] }