mongodb操做技巧

一、添加字段或更新值mongodb

db.getCollection( 'test').updateMany( {}, { $set:{ 'createTime':'2017-06-29 08:08', 'updateTime':'2017-06-29 08:08 } } );


二、更新字段類型和值
db.getCollection('coinreviews').find({}).forEach(
    function(x){
        x.groupSize = new NumberInt(x.groupSize);// 將字符串轉化爲數字
        x.lotterySize = new NumberInt(x.lotterySize);
        db.coinreviews.save(x);//保存數據
});
 
三、查詢阻塞,數據庫壓力變大,須要kill掉耗時比較長的查詢
 

db.currentOp({"ns" : "saturn.activitylotteryticketlogs"}).inprog.forEach(function(x){數據庫

 db.killOp(x.opid)spa

})字符串

 

https://docs.mongodb.com/manual/reference/method/db.currentOp/#db.currentOpget

相關文章
相關標籤/搜索