您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關MongoDB中GridFS如何使用,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
使用GridFS簡單介紹:
列出文件:
[root@localhost ~]# mongofiles list
connected to: 127.0.0.1
此時并沒有任何文件存在。
上傳文件:
[root@localhost ~]# mongofiles put install.log -d libraray
connected to: 127.0.0.1
added file: { _id: ObjectId('5616b8c4f1403ca60b0999d0'), filename: "install.log", chunkSize: 261120, uploadDate: new Date(1444329668441), md5: "c7d8a01a077940859e773b7770d2e07e", length: 9458 }
done!
再次列出上傳的文件:
[root@localhost ~]# mongofiles list -d libraray
connected to: 127.0.0.1
install.log 9458
查看MongoDB中的數據:
[root@localhost ~]# mongo libraray
MongoDB shell version: 2.6.11
connecting to: libraray
> db.fs.files.find()
{ "_id" : ObjectId("5616b8c4f1403ca60b0999d0"), "filename" : "install.log", "chunkSize" : 261120, "uploadDate" : ISODate("2015-10-08T18:41:08.441Z"), "md5" : "c7d8a01a077940859e773b7770d2e07e", "length" : 9458 }
>
指定id:
> db.fs.files.find({"_id" : ObjectId("5616b8c4f1403ca60b0999d0")})
{ "_id" : ObjectId("5616b8c4f1403ca60b0999d0"), "filename" : "install.log", "chunkSize" : 261120, "uploadDate" : ISODate("2015-10-08T18:41:08.441Z"), "md5" : "c7d8a01a077940859e773b7770d2e07e", "length" : 9458 }
> db.fs.chunks.find({},{"data":0})
{ "_id" : ObjectId("5616b8c4d2b40c73cbf811c8"), "files_id" : ObjectId("5616b8c4f1403ca60b0999d0"), "n" : 0 }
搜索文件:
[root@localhost ~]# cat testfile
hello abc
[root@localhost ~]# mongofiles put testfile -d libraray
connected to: 127.0.0.1
added file: { _id: ObjectId('5616bd093be512c2e45d0351'), filename: "testfile", chunkSize: 261120, uploadDate: new Date(1444330761770), md5: "563427968920fcf5177c6753bd6cbae3", length: 10 }
done!
[root@localhost ~]# mongofiles search test -d libraray
connected to: 127.0.0.1
testfile 10
(貌似無法搜索文件內容!!!)
刪除文件:
[root@localhost ~]# mongofiles delete testfile -d libraray
connected to: 127.0.0.1
done!
[root@localhost ~]# mongofiles search test -d libraray
connected to: 127.0.0.1
獲取文件:
[root@localhost ~]# ls
anaconda-ks.cfg install.log install.log.syslog modb testfile
[root@localhost ~]# rm -rf install.log
[root@localhost ~]# mongofiles get install.log -d libraray
connected to: 127.0.0.1
done write to: install.log
[root@localhost ~]# ls
anaconda-ks.cfg install.log install.log.syslog modb testfile
測試上傳大文件:
[root@localhost ~]# du -h 2290944.zip
3.2G 2290944.zip
[root@localhost ~]# mongofiles put 2290944.zip -d libraray
connected to: 127.0.0.1
added file: { _id: ObjectId('5616c158bfb7f87bb8e48d44'), filename: "2290944.zip", chunkSize: 261120, uploadDate: new Date(1444331976703), md5: "6fc45dd991d89db358194eba0b565f30", length: 3372909855 }
done!
> db.fs.chunks.find({"files_id":ObjectId("5616c158bfb7f87bb8e48d44")},{"data":0}).sort({n:-1}).limit(1)
{ "_id" : ObjectId("5616c1a2d2b40c73cbf84467"), "files_id" : ObjectId("5616c158bfb7f87bb8e48d44"), "n" : 12917 }
看完上述內容,你們對MongoDB中GridFS如何使用有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。