MongoDB GridFS规范

This is being changed for 2.4.10 and 2.6.0-rc3. Tyler Brock‘s explanation:

Now that the server uses power of 2 by default, if the default chunk size for gridfs is 256k we will almost always be throwing away some storage space. This is because if the bindata field of a chunk will occupy 256k (an exact power of 2), then _id and foreign key reference to the files collection, etc will take up additional space that will cause the document‘s allocated storage to be rounded up to 512k (the next power of 2). This would be a huge waste.

Instead, if we make the default chunk size 255k then we have an extra 1k to store the _id and other metadata so that when the document is persisted we round up to 256k and not 512k upon persisting the document.

MongoDB从2.4.10开始将默认的chunkSize修改为255KB,之前都是256KB。上面这段话说明了为什么要修改,原来mongodb的服务器总是以2^n个字节获取空间的,当默认设置的chunkSize为256K的时候,binaryData将会消耗掉256K的空间,而其他的字段如_id, file_ids 和 n 就会占用额外的几十个字节的空间。这样一来就会超过256K,那么服务器就会给每一个chunk分配512K,这样浪费就大了。。。。。

The chunks Collection

Each document in the chunks collection represents a distinct chunk of a file as represented in the GridFSstore. The following is a prototype document from the chunks collection.:

{
  "_id" : <ObjectId>,
  "files_id" : <ObjectId>,
  "n" : <num>,
  "data" : <binary>
}

A document from the chunks collection contains the following fields:

chunks._id

The unique ObjectId of the chunk.

chunks.files_id

The _id of the “parent” document, as specified in the files collection.

chunks.n

The sequence number of the chunk. GridFS numbers all chunks, starting with 0.

chunks.data

The chunk’s payload as a BSON binary type.

The chunks collection uses a compound index on files_id and n, as described in GridFS Index.

The files Collection

Each document in the files collection represents a file in the GridFS store. Consider the following prototype of a document in the files collection:

{
  "_id" : <ObjectId>,
  "length" : <num>,
  "chunkSize" : <num>,
  "uploadDate" : <timestamp>,
  "md5" : <hash>,

  "filename" : <string>,
  "contentType" : <string>,
  "aliases" : <string array>,
  "metadata" : <dataObject>,
}

Documents in the files collection contain some or all of the following fields. Applications may create additional arbitrary fields:

files._id

The unique ID for this document. The _id is of the data type you chose for the original document. The default type for MongoDB documents is BSON ObjectId.

files.length

The size of the document in bytes.

files.chunkSize

The size of each chunk. GridFS divides the document into chunks of the size specified here. The default size is 255 kilobytes.

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

files.uploadDate

The date the document was first stored by GridFS. This value has the Date type.

files.md5

An MD5 hash returned by the filemd5 command. This value has the String type.

files.filename

Optional. A human-readable name for the document.

files.contentType

Optional. A valid MIME type for the document.

files.aliases

Optional. An array of alias strings.

files.metadata

Optional. Any additional information you want to store.

MongoDB GridFS规范

时间: 2024-07-28 12:52:28

MongoDB GridFS规范的相关文章

第二部分 应用篇 第六章 MongoDB GridFS

声明:该文章主要来自<MongoDB实战>一书内容,主要想通过该书学习MongoDB的相应知识,加深理解,故写在自己的博文当中,作为记录,在最后的章节中,会有一个自己集合MongoDB数据库应用的JavaEE的web应用. 1.简介 GridFS是一种将大型文件存储在MongoDB数据库中的文件规范,所有官方支持的驱动均实现了GridFS规范. 1.1.为什么要用GirdFS 由于MongoDB中BSON对象大小是有限制的,所有GridFS规范提供了一种透明的机制,可以将一个大文件分割成为多个

mongodb Gridfs操作

GridFS 介绍 GridFS是MongoDB规范用于存储和检索大文件,如图片,音频文件,视频文件等.这是一种文件系统用来存储文件,但数据存储于MongoDB集合中.GridFS存储文件比其文档大小16MB限制的更大能力. GridFS的划分一个文件分成块存储数据每个块在一个单独的文件,每个最大尺寸255K. GridFS默认使用两个集合 fs.files 和 fs.chunks 存储该文件的元数据和块.每组块标识其唯一的_id ObjectID字段.fs.files切断作为父文件. fs.c

【转发】mongodb Gridfs操作

原文链接:https://www.cnblogs.com/wangjing666/p/6844598.html GridFS 介绍 GridFS是MongoDB规范用于存储和检索大文件,如图片,音频文件,视频文件等.这是一种文件系统用来存储文件,但数据存储于MongoDB集合中.GridFS存储文件比其文档大小16MB限制的更大能力. GridFS的划分一个文件分成块存储数据每个块在一个单独的文件,每个最大尺寸255K. GridFS默认使用两个集合 fs.files 和 fs.chunks 存

【转】PHP操作MongoDB GridFS 存储文件

PHP操作MongoDB GridFS 存储文件,如图片文件 GridFS是MongoDB的一个内置功能,它提供一组文件操作的API以利用MongoDB存储文件,GridFS的基本原理是将文件保存在两个Collection中,一个保存文件索引,一个保存文件内容,文件内容按一定大小分成若干块,每一块存在一个Document中,这种方法不仅提供了文件存储,还提供了对文件相关的一些附加属性(比如MD5值,文件名等等)的存储.

MongoDB GridFS最佳应用概述

<MongoDB GridFS最佳应用概述> 作者:chszs,转载需注明.博客主页:http://blog.csdn.net/chszs GridFS是MongoDB数据库之上的一个简单文件系统抽象.如果你熟悉Amazon S3的话,那么GridFS与之相似.为什么像MongoDB这样的NoSQL数据库会提供这样的一个文件层抽象呢? 一.使用GridFS的理由 理由如下: 1)存储用户产生的文件内容 大多数Web应用都允许用户上传文件.当用户使用关系数据库时,这些用户产生的文件会存储在文件系

mongodb gridfs基本使用

Mongodb GridFS图片文件存储解决方案 之前解决方案是接收图片数据后,将图片直接存储到盘阵,然后通过Apache做服务器,将图片信息存储到数据库,并且存储一个Apache的访问路径. 目前需要后台服务存储图片,将图片存储到MongoDB集群中,然后通过Nginx中的nginx-gridfs模块进行访问,在浏览器中通过url访问,效果与Apache访问本地文件一样. 本方案的内容比较基础,以后会有深入了解和优化,敬请期待! 一.安装MongoDB (1)安装MongoDB 进入计划安装目

MongoDb GridFS的使用

MongoDb GridFS 是MongoDB的文件存储方案,主要用于存储和恢复那些超过16M(BSON文件限制)的文件(如:图片.音频等),对大文件有着更好的性能. 要在C#中使用GridFS,首先安装Nuget包: MongoDB.Driver.GridFS Bucket GridFS中的数据也是分集合存储的,每个集合叫一个bucket,每个bucket里面可以存储多个文件: 在C#中使用bucket和使用集合差不多,创建一个GridFSBucket对象即可. var bucket = ne

MongoDB(八)Mongodb——GridFS存储

mongoDB的文档以BSON格式存储,支持二进制的数据类型,当我们把二进制格式的数据直接保存到mongoDB的文档中.但是当文件太大时,例如图片和视频等文件,每个文档的长度是有限的,于是mongoDb会提供了一种处理大文件的规范--GridFS. GridFS实现原理 在GridFS数据库中,默认使用fs.chunks 和fs.files来存储文件,其中fs.files集合存放文件的信息,fs.chunks存放文件的数据,一个fs.files集合中的一条记录内容如下,即一个file信息如下所示

MongoDB——GridFS

GridFS是一个规范的存储和检索文件超过16 mb的bson文档大小限制. 而不是将文件存储在一个文档中,GridFS文件分为部分,或块,每个块作为一个单独的文档.使用FridFS与使用分片无 关.在默认情况下网格文件系统块大小限制为255 k.GridFS文件系统使用两个集合存储文件.一个收集存储文件块, 其他商店文件元数据. 当你查询GridFS文件系统存储文件时,驱动或客户端将重新组装块.你可以通过GridFS文件系统上执行范围查询 文件存储.你也可以从任意部分的文件访问信息,你可以"跳