设为首页 加入收藏

TOP

使用mongofiles操作GridFS
2014-11-24 08:11:57 来源: 作者: 【 】 浏览:2
Tags:使用 mongofiles 操作 GridFS
使用mongofiles操作GridFS
GridFS描述:
GridFS,看起来像一种文件系统,其实是一种数据库用法。主要用来在数据库中存储二进制大文件。可以统一用数据库处理数据,而无需借助外部的文件系统。另外,还可以利用MongoDB的复制或者是分片机制,其故障恢复和可扩展性较好。使用这种方式存储,可以避免使用文件系统的某些限制,例如平台的差异性导致存储需要做特殊处理(Linux在同一目录下的文件数限制),还可以避免文件碎片(MongoDB分配空间以2GB作为单位),这样数据存放相对较集中,即使有文件碎片,相对来说,其程度也要比操作系统的碎片程度低得多。
操作环境:Win8 64位操作系统, 虚拟机 CentOS5.5.
操作步骤:
    (1) 启动mongoDB服务器:

[plain] 
[root@h3 ~]# mongod -f /etc/mongod.conf  
Mon Aug 12 13:07:19.737  
Mon Aug 12 13:07:19.739 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.  
Mon Aug 12 13:07:19.740  
about to fork child process, waiting until server is ready for connections.  
forked process: 22881  
all output going to: /var/log/mongo/mongod.log  
child process started successfully, parent exiting  
[root@h3 ~]#  

     (2)准备文件:
[plain] 
[root@h3 dbs]# echo 'hello mongoDB' >> test.txt  
[root@h3 dbs]# cat test.txt  
hello mongoDB  

  (3)将文件写入mongoDB:
[plain] 
[root@h3 dbs]# mongofiles put test.txt  
connected to: 127.0.0.1  
added file: { _id: ObjectId('520871172918b24487573832'), filename: "test.txt", chunkSize: 262144, uploadDate: new Date(1376284952450), md5: "f595caa8025995fab85484de67dc8549", length: 14 }  
done!  

  (4) 查看文件:
[plain] 
[root@h3 dbs]# mongofiles list  
connected to: 127.0.0.1  
test.txt        14  

    (5)删除建立的test.txt文件:

[plain] 
[root@h3 dbs]# rm -rf test.txt  

   (6)查看数据:
[plain] 
[root@h3 dbs]# mongofiles get test.txt  
connected to: 127.0.0.1  
done write to: test.txt  
[root@h3 dbs]# cat test.txt  
hello mongoDB  

操作完成!
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇解决MySQL查询不区分大小写 下一篇快速升级MySQL系统表

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·我的Linux内核学习笔 (2025-12-26 22:21:10)
·如何评价腾讯开源的 (2025-12-26 22:21:07)
·为什么TCP网络编程中 (2025-12-26 22:21:04)
·Python 数据分析与可 (2025-12-26 21:51:20)
·从零开始学Python之 (2025-12-26 21:51:17)