MongoDB 常用shell整理 四

1、根据username修改age

>db.employee.update({username:'jim'},{$set:{age:22}},false,true);

db.collection.update(criteria,objNew,upsert,multi)
criteria:update的查询条件,类似sqlupdate查询内where后面的
objNew:update的对象和一些更新的操作符(如$,$inc…)等,也可以理解为sqlupdate查询内set后面的
upsert:如果不存在update的记录,是否插入objNew,true为插入,默认是false,不插入。
multi:mongodb默认是false,只更新找到的第一条记录,如果这个参数为true,就把按条件查出来多条记录全部更新。
2、将指定username的age字段增加5

>db.mycollection.update({username:'jim'},{$inc:{age:5}},false,true);

将username为‘jim’的age字段加5
3、删除username为'rose'的数据

>db.mycollection.remove({uname:'rose'});

4、集合collection重命名

>db.mycollection.renameCollection('c_temp');

将mycollection集合重命名为'c_temp'
5、删除集合

>db.c_temp.drop();

删除名为'c_temp'的集合
6、删除当前数据库

>db.dropDatabase();

以上内容整理自:http://blog.csdn.net/xyz_lmn/article/details/8072621


未经允许不得转载:阿藏博客 » MongoDB 常用shell整理 四

赞 (0) 打赏