您好,登錄后才能下訂單哦!
GridFS作為MongoDB的存儲機(jī)制,用來存放二進(jìn)制大文件;
GridFS有以下優(yōu)點(diǎn):
(1)使用GridFS簡化存儲棧,在MongoDB中替代獨(dú)立的存儲工具;
(2)GridFS會自動平衡已有的復(fù)制和自動分片,對文件存儲做故障轉(zhuǎn)移揮著橫向擴(kuò)展會更容易;
(3)MongoDB中以2GB的大小來分配數(shù)據(jù)文件,在GridFS中文件存儲集中度會比較高;
GridFS當(dāng)然也有缺點(diǎn):
(1)從GridFS中讀取文件沒有直接從文件系統(tǒng)中快;
(2)修改存放在GridFS中的文檔,只有先刪除就文檔然后從新保存文檔;
(3)如果大文件作為多個文件存儲,修改這個大文檔時無法對所有的文件塊加鎖;
針對上述的優(yōu)缺點(diǎn),可以看出,GridFS比較適合存放不常修改的大文件。
使用mongofiles管理GrideFS
(1)用—help來查看mongofiles參數(shù)
[root@localhost ~]# mongofiles --help Browse and modify a GridFS filesystem.
(2)上傳一個文件到數(shù)據(jù)庫foo中的GridFS
[root@localhost ~]# echo "hello world" >foo.txt [root@localhost ~]# mongofiles -d foo put foo.txt connected to: 127.0.0.1 added file: { _id: ObjectId('54b3d62983047a88669bc529'), filename: "foo.txt", chunkSize: 261120, uploadDate: new Date(1421071914003), md5: "6f5902ac237024bdd0c176cb93063dc4", length: 12 } done!
(3)列出GridFS中存儲的文檔
[root@localhost ~]# mongofiles -d foo list connected to: 127.0.0.1 foo.txt 12
(4)將文檔中GridFS中下載到文件系統(tǒng)中
[root@localhost ~]# rm foo.txt rm: remove regular file `foo.txt'? y [root@localhost ~]# mongofiles -d foo get foo.txt connected to: 127.0.0.1 done write to: foo.txt [root@localhost ~]# cat foo.txt hello world
(5)搜索和刪除文檔
[root@localhost ~]# mongofiles -d foo search foo.txt connected to: 127.0.0.1 foo.txt 12 [root@localhost ~]# mongofiles -d foo delete foo.txt connected to: 127.0.0.1 done! [root@localhost ~]# mongofiles -d foo search foo.txt connected to: 127.0.0.1 [root@localhost ~]#
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。