热门标签 | HotTags
当前位置:  开发笔记 > 数据库 > 正文

MongoDB与GridFS文件系统

GridFS用于存储和恢复那些超过16M(BSON文件限制)的文件。GridFS将文件分成大块,将每个大块存储为单独的文件.GridFS中限制chunk最大为256k。GridFS使用两个collection存储,一个存储chunks,一个存储元数据(metadata)。fs.files和fs.chunksWhensh


GridFS用于存储和恢复那些超过16M(BSON文件限制)的文件。

GridFS将文件分成大块,将每个大块存储为单独的文件.GridFS中限制chunk最大为256k。GridFS使用两个collection存储,一个存储chunks,一个存储元数据(metadata)。
fs.files和fs.chunks


When should I use GridFS?
http://docs.mongodb.org/manual/faq/developers/#faq-developers-when-to-use-gridfs

 


file Collection:具体形式如下
{
  "_id" : ,
  "length" : ,
  "chunkSize" :
  "uploadDate" :
  "md5" :

  "filename" : ,
  "contentType" : ,
  "aliases" : ,
  "metadata" : ,
}

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 256 kilobytes.

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

files.md5
    An MD5 hash returned from the filemd5 API. 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.

The chunks Collection:举例如下
{
  "_id" : ,
  "files_id" : ,
  "n" : ,
  "data" :
}

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.

GridFS Index

GridFS使用chunks中files_id和n域作为混合索引,files_id是父文档的_id,n域包含chunk的序列号,该值从0开始。
GridFS索引支持快速恢复数据。

cursor = db.fs.chunks.find({files_id: myFileID}).sort({n:1});

如果没有建立索引,可以使用下列shell命令:
db.fs.chunks.ensureIndex( { files_id: 1, n: 1 }, { unique: true } );

Example Interface:

// returns default GridFS bucket (i.e. "fs" collection)
GridFS myFS = new GridFS(myDatabase);

// saves the file to "fs" GridFS bucket
myFS.createFile(new File("/tmp/largething.mpg"));

接口支持额外的GridFS buckets
// returns GridFS bucket named "contracts"
GridFS myCOntracts= new GridFS(myDatabase, "contracts");

// retrieve GridFS object "smithco"
GridFSDBFile file = myContracts.findOne("smithco");

// saves the GridFS file to the file system
file.writeTo(new File("/tmp/smithco.pdf"));


推荐阅读
  • python中安装并使用redis相关的知识
    本文介绍了在python中安装并使用redis的相关知识,包括redis的数据缓存系统和支持的数据类型,以及在pycharm中安装redis模块和常用的字符串操作。 ... [详细]
  • Allegro总结:1.防焊层(SolderMask):又称绿油层,PCB非布线层,用于制成丝网印板,将不需要焊接的地方涂上防焊剂.在防焊层上预留的焊盘大小要比实际的焊盘大一些,其差值一般 ... [详细]
  • 1.淘宝模拟登录2.天猫商品数据爬虫3.爬取淘宝我已购买的宝贝数据4.每天不同时间段通过微信发消息提醒女友5.爬取5K分辨率超清唯美壁纸6.爬取豆瓣排行榜电影数据(含GUI界面版) ... [详细]
  • SeMITechnologies正在使用矢量搜索引擎Weaviate构建的内容。SeMI的首席执行官兼联合创始人BobvanLuijt说,它是一种独特的AI优先数据库,使用机器学习 ... [详细]
  • Abp+MongoDb改造默认的审计日志存储位置
    一、背景在实际项目的开发当中,使用AbpZero自带的审计日志功能写入效率比较低。其次审计日志数据量中后期十分庞大,不适合与业务数据存放在一起。所以我们可以重新实现A ... [详细]
  • 今天我们学习,数据库mongodb的使用,最下面有mongodb的下载链接。pipinstallpymongo首先安装pymongo,然后在需要用到的地方importpymongo ... [详细]
  • MongoDB学习:(二)MongoDB简单使用
    MongoDB学习:(二)MongoDB简单使用MongoDB使用:执行mongodb的操作之前,我们需要运行命令,来进入操作命令界面>mongo提示 ... [详细]
  •     系统采用jeeplus框架(ssm+redis+shiro+mongodb+redis),默认是做了JSP未做前后端分离,由于业务需要已经多终端使用的需求(H5、小程序等) ... [详细]
  • mongoDB高可用集群环境搭建
    2019独角兽企业重金招聘Python工程师标准在生产环境下,部署一台mongodb服务的话,会存在以下问题:单点问题生产环境是一个 ... [详细]
  • 篇首语:本文由编程笔记#小编为大家整理,主要介绍了Mongodb副本集+分片集群搭建相关的知识,希望对你有一定的参考价值。环境需求: ... [详细]
  • 这是我的第一篇博客,多有不足请指教,话不多说,直入正题原因:由于mongodb数据量较大,占用空间较大,所以决定转移数据目录到另一块磁盘下一、查看磁盘占用情况[root@test~ ... [详细]
  • 前面刚有AWS开战MongoDB,双方“隔空互呛”,这厢又曝出2亿+简历信息泄露——MongoDB的这场开年似乎“充实”得过分了些。长期以来,作为“最受欢迎的NoSQL数据库”,M ... [详细]
  • Java开发面试问题,2021网易Java高级面试题及答案,实战案例
    前言大厂面试真题向来都是各大求职者的最佳练兵场,而今天小编带来的便是“HUAWEI”面经!这是一次真实的面试经历,虽然不是我自己亲身经历 ... [详细]
  • 数据库基本介绍
    1、数据库基本知识概念:数据库:database(DB),是一种存储数据的仓库数据库是根据数据结构组织、存储和 ... [详细]
  • 关于mysql原理与web系统开发的信息
    本文目录一览:1、在做web开发的时候,MySQL主要功能是什么? ... [详细]
author-avatar
手机用户2502915601
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有