赞
踩
mongodb删除亿级数据
- 我们的数据是这样的,我们取前10条
- > db.device_state.find().limit(10)
- { "_id" : NumberLong(200000), "_class" : "com.iot.device.model.DeviceState", "deviceId" : "5799edd59da13a2c62b5108a6d78e201", "propertyName" : "Tamper", "propertyValue" : "1", "productId" : NumberLong(183), "logDate" : ISODate("2019-10-31T13:50:00.078Z"), "tenantId" : NumberLong(2) }
-
-
- 写脚本分批删除数据
- mongo --port 30000 -u admin -p 123456 iot_db_control device_log_delete.js
-
- cat device_log_delete.js
-
- try{
- for (var i = 7000000 ; i <= 15000000; i +=30000){
- print("delete_id: "+ i);
- db.device_log.deleteMany({"_id":{$lte : i , $gte : i-30000}})
- sleep (2000);
- };
-
- }
-
- catch (e) {
- print(e);
- }
-
- 根据负载,sleep时间可以调整
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。