香港云主机最佳企业级服务商!

ADSL拨号VPS包含了中国大陆(联通,移动,电信,)

中国香港,国外拨号VPS。

当前位置:云主机 > Mongodb >

电信ADSL拨号VPS
联通ADSL拨号VPS
移动ADSL拨号VPS

Mongodb批量删除gridfs文件实例


时间:2020-11-14 13:35 作者:admin


平台有大量的图片已经不用了,数量级达到百万张,差不多100G的空间,放着不管是不是太浪费了?
复制代码 代码如下:
db.fs.files.find({filename:/xxx/}).forEach(function(n) {db.fs.files.update({filename:u.filename},{$set:{filename:newname}},false,true)}} //正则批量更改为固定名称,便于删除。
mongofiles -port 12345 -d xxx delete newname //mongofies根据filename批量干掉这些文件。

db.repairDatabase() //特别注意以上删除不是物理删除,chunks文件实际还在,show dbs 或者 db.stats() 发现db的size没有变化,要执行db.repairDatabase();另外注意这个动作是全局写锁,很耗内存和cpu的,而且处理时间跟文件数量大小有关,务必在非高峰期做。

差不多1个多小时后over, 舒坦了,100G空间啊!!!

Be aware that this command can take a long time to run if your database is large. In addition, it requires a quantity of free disk space equal to the size of your database. If you lack sufficient free space on the same volume, you can mount a separate volume and use that for the repair. In this case, you must run the command line and use the –repairpath switch to specify the folder in which to store the temporary repair files.
Warning:This command obtains a global write lock and will block other operations until it has completed.

(责任编辑:admin)






帮助中心
会员注册
找回密码
新闻中心
快捷通道
域名登录面板
虚机登录面板
云主机登录面板
关于我们
关于我们
联系我们
联系方式

售前咨询:17830004266(重庆移动)

企业QQ:383546523

《中华人民共和国工业和信息化部》 编号:ICP备00012341号

Copyright © 2002 -2018 香港云主机 版权所有
声明:香港云主机品牌标志、品牌吉祥物均已注册商标,版权所有,窃用必究

云官方微信

在线客服

  • 企业QQ: 点击这里给我发消息
  • 技术支持:383546523

  • 公司总台电话:17830004266(重庆移动)
  • 售前咨询热线:17830004266(重庆移动)