手机
当前位置:查字典教程网 >编程开发 >MongoDB >Mongodb批量删除gridfs文件实例
Mongodb批量删除gridfs文件实例
摘要:平台有大量的图片已经不用了,数量级达到百万张,差不多100G的空间,放着不管是不是太浪费了?复制代码代码如下:db.fs.files.fin...

平台有大量的图片已经不用了,数量级达到百万张,差不多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入门教程之C#驱动操作实例

MongoDB的PHP驱动方法与技巧

MongoDB中强大的统计框架Aggregation使用实例解析

Mongodb安装与配置笔记

MongoDB单表数据的导出和恢复实例讲解

mongodb 添加用户及权限设置详解

MongoDB的安装及配置文件选项全解

mongodb 集群重构和释放磁盘空间实例详解

MongoDB日志文件过大的解决方法

PHP中MongoDB数据库的连接、添加、修改、查询、删除等操作实例

精品推荐
分类导航