Mongodb批量刪除gridfs文件實(shí)例
平臺(tái)有大量的圖片已經(jīng)不用了,數(shù)量級(jí)達(dá)到百萬張,差不多100G的空間,放著不管是不是太浪費(fèi)了?
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ù)必在非高峰期做。
差不多1個(gè)多小時(shí)后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.
相關(guān)文章
MongoDB快速入門筆記(二)之MongoDB的概念及簡單操作
MongoDB是面向集合的文檔式數(shù)據(jù)庫,不像關(guān)系數(shù)據(jù)庫那樣,有表,列、行,mongoDB數(shù)據(jù)庫則是由一系列的文檔組成。接下來通過本文給大家介紹MongoDB的概念及簡單操作,一起看看吧2016-06-06如何對(duì) MongoDB 進(jìn)行性能優(yōu)化(五個(gè)簡單步驟)
MongoDB一直是最流行的NoSQL,而根據(jù)DB-Engines Ranking最新的排行,時(shí)下MongoDB已經(jīng)擊敗PostgreSQL躍居數(shù)據(jù)庫總排行的第四位,僅次于Oracle、MySQL和Microsoft SQL Server。本文給大家介紹MongoDB性能優(yōu)化的簡單總結(jié)。2015-10-10在Linux服務(wù)器中配置mongodb環(huán)境的步驟
這篇文章主要介紹了在Linux服務(wù)器中配置mongodb環(huán)境的步驟,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07MongoDB數(shù)據(jù)庫兩階段提交實(shí)現(xiàn)事務(wù)的方法詳解
這篇文章主要介紹了MongoDB數(shù)據(jù)庫兩階段提交實(shí)現(xiàn)事務(wù)的方法,結(jié)合實(shí)例形式詳細(xì)分析了MongoDB數(shù)據(jù)庫事務(wù)提交、回滾、撤銷等操作的原理、實(shí)現(xiàn)方法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2018-08-08mongodb設(shè)置后臺(tái)運(yùn)行的方法
這篇文章主要介紹了mongodb設(shè)置后臺(tái)運(yùn)行的方法,本文同時(shí)給出了關(guān)閉已在后臺(tái)運(yùn)行mongodb的方法,需要的朋友可以參考下2014-09-09Windows系統(tǒng)下安裝Mongodb 3.2.x的步驟詳解
mongodb3.x版本有好多新功能,關(guān)于這方面參考官網(wǎng)即可,下面這篇文章主要給大家介紹了在Windows系統(tǒng)下安裝Mongodb 3.2.x的詳細(xì)步驟,文中介紹的非常詳細(xì),需要的朋友們可以參考學(xué)習(xí),下面來一起看看吧。2017-03-03