`
gaojingsong
  • 浏览: 1182665 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

【MongoDB之GridFS 】

阅读更多

GridFS is a specification for storing and retrieving files that exceed the BSON-document size limit of 16 MB.

GridFS 用于存储和恢复那些超过16M(BSON文件限制)的文件(如:图片、音频、视频等)。

GridFS 也是文件存储的一种方式,但是它是存储在MonoDB的集合中。

GridFS 可以更好的存储大于16M的文件。

GridFS 会将大文件对象分割成多个小的chunk(文件片段),一般为256k/个,每个chunk将作为MongoDB的一个文档(document)被存储在chunks集合中。

GridFS 用两个集合来存储一个文件:fs.files与fs.chunks。

每个文件的实际内容被存在chunks(二进制数据)中,和文件有关的meta数据(filename,content_type,还有用户自定义的属性)将会被存在files集合中。

 

 

Instead of storing a file in a single document, GridFS divides the file into parts, or chunks , and stores each chunk as a separate document. By default, GridFS uses a chunk size of 255 kB; that is, GridFS divides a file into chunks of 255 kB with the exception of the last chunk. The last chunk is only as large as necessary. Similarly, files that are no larger than the chunk size only have a final chunk, using only as much space as needed plus some additional metadata.

 

GridFS uses two collections to store files. One collection stores the file chunks, and the other stores file metadata. The section GridFS Collections describes each collection in detail.

 

When you query GridFS for a file, the driver will reassemble the chunks as needed. You can perform range queries on files stored through GridFS. You can also access information from arbitrary sections of files, such as to “skip” to the middle of a video or audio file.

 

GridFS is useful not only for storing files that exceed 16 MB but also for storing any files for which you want access without having to load the entire file into memory. See also When to Use GridFS.

 

Changed in version 2.4.10: The default chunk size changed from 256 kB to 255 kB.

 

 

When to Use GridFS

In MongoDB, 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 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.

When you want to keep your files and metadata automatically synced and deployed across a number of systems and facilities, you can use GridFS. When using geographically distributed replica sets, MongoDB can distribute files and their metadata automatically to a number of mongod instances and facilities.

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 instead of using GridFS. You may use the BinData data type to store the binary data. See your drivers documentation for details on using BinData.

 

 

为什么要用GridFS

由于MongoDB 中BSON 对象大小是有限制的,所以GridFS 规范提供了一种透明的机制,可以将一个大文件分割成为多个较小的文档,这样的机制允许我们有效的保存大文件对象,特别对于那些巨大的文件,比如视频、高清图片等。

 

 

GridFS 使用两个表来存储数据:

files 包含元数据对象

chunks 包含其他一些相关信息的二进制块

为了使多个GridFS 命名为一个单一的数据库,文件和块都有一个前缀,默认情况下,前缀是fs,所以任何默认的GridFS 存储将包括命名空间fs.files 和fs.chunks。各种第三方语言的驱动有权限改变这个前缀,所以你可以尝试设置另一个GridFS 命名空间用于存储照片,它的具体位置为:photos.files 和photos.chunks。

 

32-bit MongoDB processes are limited to about 2 gb of data. This has come as a surprise to a lot of people who are used to not having to worry about that. The reason for this is that the MongoDB storage engine uses memory-mapped files for performance.

 

By not supporting more than 2gb on 32-bit, we’ve been able to keep our code much simpler and cleaner. This greatly reduces the number of bugs, and reduces the time that we need to release a 1.0 product. The world is moving toward all 64-bit very quickly. Right now there aren’t too many people for whom 64-bit is a problem, and in the long term, we think this will be a non-issue.

0
1
分享到:
评论

相关推荐

    MongoDB.GridFS.dll

    MongoDB.GridFS.dll c#类库...............................................

    Mongodb基于GridFS存储文件

    Mongodb基于GridFS存储文件,通过流的方式存储文件图片,以及读取功能。本人亲自测试、编写。值得信赖

    MongoDB的GridFS:存储大文件的解决方案.rar

    GridFS简介 什么是GridFS GridFS的工作原理 GridFS的应用场景 安装与配置 安装MongoDB 安装MongoDB驱动 GridFS基本操作 文件的上传 文件的下载 文件的删除 GridFS高级操作 文件分片与元数据管理 并发文件操作 文件...

    Mongodb的gridfs的C#的例子

    MongoDB的GridFS是一种用于存储和检索大文件的系统,它是MongoDB数据库的一部分,特别适合存储超过16MB的单个文档。在C#中,我们可以利用MongoDB .NET驱动程序来操作GridFS。以下是对GridFS在C#中使用的详细讲解。 ...

    MongoDB-GridFS-test:从MongoDB GridFS下载文件的性能测试

    我正在尝试从GridFS读取3种不同的部署(不同的MongoDB驱动程序)。 并将结果与​​经典的Nginx配置进行比较。贡献者( ) ( )构型1,Nginx location /files/ { alias /home/ubuntu/;}测试期间, open_file_cache...

    mongodb+GridFS文件的上传下载删除DEMO

    GridFS 是 MongoDB 提供的一种用于存储和检索大型文件(如图片、视频等)的标准机制,将大文件分成多个小块存储在 MongoDB 的集合中,以提高效率和可靠性。 在这个"mongodb+GridFS文件的上传下载删除DEMO"项目中,...

    Mongodb + GridFS +Java 操作Mongodb中存储的文件

    GridFS 是 MongoDB 提供的一种用于存储和检索大型文件的标准规范,它将大文件分割成多个小块(chunks)存储,方便高效管理和检索。在这个Java操作MongoDB中存储的文件实例中,我们将探讨如何利用GridFS API进行文件...

    MongoDB数据库GRIDFS上传下载删除文件

    在MongoDB中,GRIDFS是一种特殊的数据存储方式,用于存储和检索大文件,如图片、视频或大型文档。它将文件分割成多个块(chunks),以便更高效地存储和检索。 1. **上传文件到MongoDB的GRIDFS** 在MongoDB中,使用...

    Mongodb与GridFS

    NULL 博文链接:https://shift-alt-ctrl.iteye.com/blog/2195646

    mongodb gridfs .NET(C#) 文件存储实例

    功能:基于mongodb gridfs实现简单文件上传、下载、搜索、删除。 开发环境:VS2012 mongodb驱动:官方Driver 上传控件:jquery uploadify 疑问:sort()方法可能有点问题 PS:有问题可以留言,欢迎交流~

    gridfs2s3:将 MongoDB GridFS 文件迁移到 AWS S3 的工具

    gridfs2s3 - 将 MongoDB GridFS 文件迁移到 AWS S3 的工具 这是一个简单的工具,它将抓取您指向的 GridFS 中的所有文件,并将它们粘贴到 S3 中 安装 go install github.com/Bowbaq/gridfs2s3 用法 gridfs2s3 -h flag...

    MongoDB学习笔记之GridFS使用介绍

    MongoDB的GridFS是一个强大的文件存储系统,专为在数据库中存储和检索大量小文件而设计。GridFS将文件拆分为多个数据块(chunk),每个块都有自己的文档存储在`fs.chunks`集合中,而文件元信息则保存在`fs.files`集合...

    基于spring-boot和mongodb gridfs文件系统的文件服务器,用于微服务架构的文件上传下载功能支撑.zip

    基于node.js、vue、mongodb等技术构建的web系统,界面美观,功能齐全,适合用作毕业设计、课程设计作业等,项目均经过测试,可快速部署运行! 基于node.js、vue、mongodb等技术构建的web系统,界面美观,功能齐全,...

    Vue+axios+Spring Boot+mongoDB 基于Mongo图片存储和基于GridFS的文件存储.zip

    这个压缩包"Vue+axios+Spring Boot+mongoDB 基于Mongo图片存储和基于GridFS的文件存储.zip"提供了一个完整的解决方案,结合了前端Vue.js框架、axios库、后端Spring Boot微服务以及MongoDB数据库的GridFS文件系统,...

    Mongodb GridFS图片文件存储解决方案

    GridFS 是 MongoDB 提供的一种用于存储和检索大文件的标准方法,如图片、视频或大型文档。在本文中,我们将深入探讨 GridFS 图片文件存储解决方案及其工作原理。 **GridFS 概述** GridFS 是 MongoDB 的一部分,它将...

    MongoDB GridFS.pdf

    MongoDB GridFS 是一种在 MongoDB 数据库中存储和检索大型文件(如图片、音频、视频等)的机制。由于 MongoDB 的 BSON 文档格式对单个文档的大小有限制(默认为 16MB),GridFS 提供了一种解决方案,它将大文件分割...

    Laravel开发-laravel-gridfs-storage

    在本文中,我们将深入探讨Laravel开发中的一个特殊组件——`laravel-gridfs-storage`,这是一个将MongoDB的GridFS存储系统与Laravel框架的存储API整合的工具。MongoDB GridFS是一种分布式文件存储系统,它允许我们以...

    使用java上传MP4文件至mongodb数据库,并下载 源代码

    MongoDB中的GridFS是用于存储大文件的标准,它将文件拆分为多个小块(chunks),便于高效存储和检索。GridFS分为两个集合:`files`用于存储文件元数据,`chunks`用于存储文件内容。 上传MP4文件到GridFS,首先创建...

    Mongodb批量删除gridfs文件实例

    GridFS 是 MongoDB 内置的一个文件系统,用于存储和检索大文件,如图片、视频等。当你的应用不再需要某些文件,例如大量的图片,进行批量删除可以回收宝贵的存储空间。下面将详细介绍如何在 MongoDB 中批量删除 ...

    MongoDB GridFS方式增删改图片代码

    网站大量图片存储需要用到Mongodb,本代码中以图片上传、图片更新、图片删除为例子,展示了以GridFS方式对文件进行存取。

Global site tag (gtag.js) - Google Analytics