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根據(jù)filename批量干掉這些文件。
db.repairDatabase() //特別注意以上刪除不是物理刪除,chunks文件實(shí)際還在,show dbs 或者 db.stats() 發(fā)現(xiàn)db的size沒有變化,要執(zhí)行db.repairDatabase();另外注意這個(gè)動(dòng)作是全局寫鎖,很耗內(nèi)存和cpu的,而且處理時(shí)間跟文件數(shù)量大小有關(guān),務(wù)必在非高峰期做。
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.