MongoDB中GridFS如何使用
admin
2023-04-11 19:03:31
0

使用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 }

相关内容

热门资讯

今日重大消息“开心安徽比鸡可以... 有 亲,根据资深记者爆料开心安徽比鸡是可以开挂的,确实有挂(咨询软件无需...
【第一资讯】“阿道夫游戏开挂神... 您好:阿道夫游戏这款游戏可以开挂,确实是有挂的,需要了解加客服微信【4282891】很多玩家在这款游...
玩家最新攻略“小闲川南棋牌开挂... 家人们!今天小编来为大家解答小闲川南棋牌透视挂怎么安装这个问题咨询软件客服徽4282891的挂在哪里...
今日重大通报“友谊互娱有挂吗?... 今日重大通报“友谊互娱有挂吗?”(果然有透视挂)您好,友谊互娱这个游戏其实有挂的,确实是有挂的,需要...
今日重大通报“全民如意棋牌开挂... 您好:全民如意棋牌这款游戏可以开挂,确实是有挂的,需要了解加客服微信【4282891】很多玩家在这款...
终于明白“胡乐邯郸麻将开挂器?... 家人们!今天小编来为大家解答胡乐邯郸麻将透视挂怎么安装这个问题咨询软件客服徽9752949的挂在哪里...
【今日要闻】“上海滩到底有挂吗... 家人们!今天小编来为大家解答上海滩透视挂怎么安装这个问题咨询软件客服徽9752949的挂在哪里买很多...
终于懂了“麦穗app推筒子究竟... 网上科普关于“麦穗app推筒子有没有挂”话题很是火热,小编也是针对麦穗app推筒子作*弊开挂的方法以...
终于了解“网易棋牌可以开挂吗?... 家人们!今天小编来为大家解答网易棋牌透视挂怎么安装这个问题咨询软件客服徽4282891的挂在哪里买很...
重磅消息“衢州都莱怎么开挂?”... 网上科普关于“衢州都莱有没有挂”话题很是火热,小编也是针对衢州都莱作*弊开挂的方法以及开挂对应的知识...