posts - 28,  comments - 15,  trackbacks - 0

对于MongoDB collection下的文档而言,在文件大于16MB时,我们应该使用GridFS。

在一些解决方案中,使用MongoDB的GridFS存储大文件,比使用系统级别的文件系统更便利。
.当文件系统的目录对文件数量有限制时,你应该使用GridFS来存储需要的尽可能多的文件;
.当你想让你的文件和元数据在多个系统和设施之间自动同步和部署时。使用地理上分布的副本集(geographically distributed replica sets),MongoDB可以自动地分发文件和元数据到多个mongo实例和设施上。
.当你想访问大文件的部分信息,而又不想把整个文件加载到内存时,你可以使用GridFS调回部分文件,而不用把整个文件读入到内存。

如果你需要自动的更新文件的整个内容,不要使用GridFS.作为替代,你可以存储文件的多个版本,并且在元数据中指定文件的当前版本。在上传新版本的文件后,你可以以原子更新来更新表示为"latest"的元数据字段,如果需要的话,你可以删除以前的版本。

For documents in a MongoDB collection, you should always use GridFS for storing files larger than 16 MB.

In some situations, storing large files may be more efficient in a MongoDB database than on a system-level filesystem.

  • If your filesystem limits the number of files in a directory, you can use GridFS to store as many files as needed.
  • When you want to keep your files and metadata automatically synced and deployed across a number of systems and facilities. When usinggeographically distributed replica sets MongoDB can distribute files and their metadata automatically to a number of mongod instances and facilities.
  • When you want to access information from portions of large files without having to load whole files into memory, you can use GridFS to recall sections of files without reading the entire file into memory.

Do not use GridFS if you need to update the content of the entire file atomically. As an alternative you can store multiple versions of each file and specify the current version of the file in the metadata. You can update the metadata field that indicates “latest” status in an atomic update after uploading the new version of the file, and later remove previous versions if needed.

Furthermore, if your files are all smaller the 16 MB BSON Document Size limit, consider storing the file manually within a single document. You may use the BinData data type to store the binary data. See your drivers documentation for details on using BinData.

For more information on GridFS, see GridFS.


地址:http://docs.mongodb.org/manual/faq/developers/#faq-developers-when-to-use-gridfs

posted on 2013-04-09 18:41 zhangxl 阅读(499) 评论(0)  编辑  收藏 所属分类: nosql

只有注册用户登录后才能发表评论。


网站导航:
 
<2013年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(1)

随笔分类(17)

随笔档案(28)

文章分类(30)

文章档案(30)

相册

收藏夹(2)

hibernate

java基础

mysql

xml

关注

压力测试

算法

最新随笔

搜索

  •  

积分与排名

  • 积分 - 95630
  • 排名 - 603

最新评论

阅读排行榜

评论排行榜