1、添加字段或更新值
db.getCollection('test').updateMany( {}, { $set:{ 'createTime':'2017-06-29 08:08', 'updateTime':'2017-06-29 08:08 } } );
2、更新字段类型和值
db.getCollection('coinreviews').find({}).forEach(
function(x){
x.groupSize = new NumberInt(x.groupSize);// 将字符串转化为数字
x.lotterySize = new NumberInt(x.lotterySize);
db.coinreviews.save(x);//保存数据
});
function(x){
x.groupSize = new NumberInt(x.groupSize);// 将字符串转化为数字
x.lotterySize = new NumberInt(x.lotterySize);
db.coinreviews.save(x);//保存数据
});
3、查询阻塞,数据库压力变大,需要kill掉耗时比较长的查询
db.currentOp({"ns" : "saturn.activitylotteryticketlogs"}).inprog.forEach(function(x){
db.killOp(x.opid)
})
https://docs.mongodb.com/manual/reference/method/db.currentOp/#db.currentOp