Mongodb如何批量删除gridfs文件

来源:爱站网时间:2020-10-31编辑:网友分享
这篇文章主要介绍了Mongodb批量删除gridfs文件实例,本文根据生产环境实际需求总结而来,需要的朋友可以参考下

当平台有大量不用图片就会占用内存,那么我们要怎么去删除这些文件呢?那么接下来的内容中就让我们一起去看看Mongodb如何批量删除gridfs文件的方法。

复制代码 代码如下:

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修改、删除文档的域属性实例

下一篇:MongoDB基本管理命令

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载