Mongodb批量删除gridfs文件实例

发布时间:2022-04-21 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了Mongodb批量删除gridfs文件实例脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

平台有大量的图片已经不用了,数量级达到百万张,差不多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.

脚本宝典总结

以上是脚本宝典为你收集整理的Mongodb批量删除gridfs文件实例全部内容,希望文章能够帮你解决Mongodb批量删除gridfs文件实例所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: