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的,而且處理時間跟文件數量大小有關,務必在非高峰期做。
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.