Mongodb
批量修改
db.xyz.updateMany(
{ 'userLevel' : { $eq: 7 } },
{
$set: { 'userLevel': '0'}
}
);
批量修改 userLevel = 7 的xyz表里的数据 为 userLevel = 0
db.getCollection('xyz').find({"toUserId":10169175,"createTime":{"$lt":1557849600}}).count()
查询表下id为10169175 创建时间小于5月15的数据
mongodb/bin 目录下
导出对应表信息
./mongoexport --host=127.0.0.1 --port=27017-d imapi -c user -f _id,nickname,phone,telephone,sex,userLevel,birthday --csv -o ./user.csv
db.getCollection('xyz').aggregate([{$match:{'status':1}},{$group:{_id:'$sellerId','totalPrice':{$sum:{$multiply:["$unitPrice","$number"]}}}}]);
db.getCollection('xyz').aggregate([{$match:{'status':1}},{$group:{_id:'$userId1','totalPrice':{$sum:"$money"}}}]);
db.getCollection('xyz').find({"name":{$in:['唐','宋','元','明','清']}})
db.getCollection('BCLTransactionRecord').aggregate([{$match:{}},{$group:{}},{$project:{}},{$sort:{}}])
match 是查询过滤条件
group 分组条件
project 显示列条件
sort 排序
//修改字段名称,把NameApply表的IDCard修改为idCard
db.getCollection('NameApply').update({}, {$rename : {"IDCard" : "idCard"}}, false, true)
//把 from这个数组有hengduan这个值,并且zhLatin是空的数据的zhLatin字段删除
db.getCollection('species').update({"from":"hengduan","zhLatin":null},{$unset:{'zhLatin':''}},false, true)
db.collection.update(criteria,objNew,upsert,multi)
参数说明:
criteria:查询条件
objNew:update对象和一些更新操作符
upsert:如果不存在update的记录,是否插入objNew这个新的文档,true为插入,默认为false,不插入。
multi:默认是false,只更新找到的第一条记录。如果为true,把按条件查询出来的记录全部更新。