Mongodb批量刪除gridfs文件實例
平臺有大量的圖片已經(jīng)不用了,數(shù)量級達到百萬張,差不多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根據(jù)filename批量干掉這些文件。
db.repairDatabase() //特別注意以上刪除不是物理刪除,chunks文件實際還在,show dbs 或者 db.stats() 發(fā)現(xiàn)db的size沒有變化,要執(zhí)行db.repairDatabase();另外注意這個動作是全局寫鎖,很耗內(nèi)存和cpu的,而且處理時間跟文件數(shù)量大小有關,務必在非高峰期做。
差不多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快速入門筆記(二)之MongoDB的概念及簡單操作
MongoDB是面向集合的文檔式數(shù)據(jù)庫,不像關系數(shù)據(jù)庫那樣,有表,列、行,mongoDB數(shù)據(jù)庫則是由一系列的文檔組成。接下來通過本文給大家介紹MongoDB的概念及簡單操作,一起看看吧2016-06-06如何對 MongoDB 進行性能優(yōu)化(五個簡單步驟)
MongoDB一直是最流行的NoSQL,而根據(jù)DB-Engines Ranking最新的排行,時下MongoDB已經(jīng)擊敗PostgreSQL躍居數(shù)據(jù)庫總排行的第四位,僅次于Oracle、MySQL和Microsoft SQL Server。本文給大家介紹MongoDB性能優(yōu)化的簡單總結(jié)。2015-10-10在Linux服務器中配置mongodb環(huán)境的步驟
這篇文章主要介紹了在Linux服務器中配置mongodb環(huán)境的步驟,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-07-07MongoDB數(shù)據(jù)庫兩階段提交實現(xiàn)事務的方法詳解
這篇文章主要介紹了MongoDB數(shù)據(jù)庫兩階段提交實現(xiàn)事務的方法,結(jié)合實例形式詳細分析了MongoDB數(shù)據(jù)庫事務提交、回滾、撤銷等操作的原理、實現(xiàn)方法及相關操作注意事項,需要的朋友可以參考下2018-08-08Windows系統(tǒng)下安裝Mongodb 3.2.x的步驟詳解
mongodb3.x版本有好多新功能,關于這方面參考官網(wǎng)即可,下面這篇文章主要給大家介紹了在Windows系統(tǒng)下安裝Mongodb 3.2.x的詳細步驟,文中介紹的非常詳細,需要的朋友們可以參考學習,下面來一起看看吧。2017-03-03