1.利用Mongofile命令进行文件的操作
usage: mongofiles.exe [options] command [gridfs filename]
command:
one of (list|search|put|get)
list - list all files. 'gridfs filename' is an optional prefix //查看所有文件
which listed filenames must begin with.
search - search all files. 'gridfs filename' is a substring //查找文件
which listed filenames must contain.
put - add a file with filename 'gridfs filename' //上传文件
get - get a file with filename 'gridfs filename' //获取文件
delete - delete all files with filename 'gridfs filename' //删除文件
options:
--help produce help message
-v [ --verbose ] be more verbose (include multiple times for more
verbosity e.g. -vvvvv)
-h [ --host ] arg mongo host to connect to ( <set name>/s1,s2 for sets
--port arg server port. Can also use --host hostname:port
--ipv6 enable IPv6 support (disabled by default)
-u [ --username ] arg username
-p [ --password ] arg password
--dbpath arg directly access mongod database files in the given
path, instead of connecting to a mongod server -
needs to lock the data directory, so cannot be used
if a mongod is currently accessing the same path
--directoryperdb if dbpath specified, each db is in a separate
directory
-d [ --db ] arg database to use
-c [ --collection ] arg collection to use (some commands)
-l [ --local ] arg local filename for put|get (default is to use the
same name as 'gridfs filename')
-t [ --type ] arg MIME type for put (default is to omit)
-r [ --replace ] Remove other files with same name after PUT
2.内部原理
GridFS基本思想是可以将大文件分成很多块,每块作为一个单独的文档存储,这样就能存大文件了。由于MongoDB支持在文档中存储二进制数据,可以最大限度减小块的存储开销。另外,除了存储文件本身的块,还有一个单独的文档用来储存分块的信息和文件的元数据。
默认情况下使用fs.chunks集合存块。其文档结构如下:
{
"_id":ObjectId("......"),
"n":0,//表示块编号
"data":BinData("...."),//二进制数据
"files_id"//包含这个块元数据的文件文档的"_id"
}
默认使用fs.file存文件的元数据
> db.fs.files.find()
{ "_id" : ObjectId("4fc86cceddc24f04eed5b200"), "filename" : "../Alfresco.txt",
"chunkSize" : 262144, "uploadDate" : ISODate("2012-06-01T07:18:38.763Z"), "md5"
: "e3c2d56f6b6cf4ec09da825e24b6c758", "length" : 1021 }
>
其中_id,文件唯一的id,在块中作为files_id键的值存储
length,文件内容总的字节数
chunkSize每块的大小,以字节为单位,默认为256K,必要时可以调整。
uploadDate 文件存储的时间戳
md5 文件内容的md5的校验和,由服务器端生成。
分享到:
相关推荐
功能:基于mongodb gridfs实现简单文件上传、下载、搜索、删除。 开发环境:VS2012 mongodb驱动:官方Driver 上传控件:jquery uploadify 疑问:sort()方法可能有点问题 PS:有问题可以留言,欢迎交流~
基于node.js、vue、mongodb等技术构建的web系统,界面美观,功能齐全,适合用作毕业设计、课程设计作业等,项目均经过测试,可快速部署运行! 基于node.js、vue、mongodb等技术构建的web系统,界面美观,功能齐全,...
gridfs2s3 - 将 MongoDB GridFS 文件迁移到 AWS S3 的工具 这是一个简单的工具,它将抓取您指向的 GridFS 中的所有文件,并将它们粘贴到 S3 中 安装 go install github.com/Bowbaq/gridfs2s3 用法 gridfs2s3 -h flag...
MongoDB GridFS.pdf 学习资料 复习资料 教学资源
主要介绍了PHP MongoDB GridFS 存储文件的方法详解的相关资料,需要的朋友可以参考下
Mongodb的gridfs的C#的例子
网站大量图片存储需要用到Mongodb,本代码中以图片上传、图片更新、图片删除为例子,展示了以GridFS方式对文件进行存取。
我正在尝试从GridFS读取3种不同的部署(不同的MongoDB驱动程序)。 并将结果与经典的Nginx配置进行比较。贡献者( ) ( )构型1,Nginx location /files/ { alias /home/ubuntu/;}测试期间, open_file_cache...
Mongodb基于GridFS存储文件,通过流的方式存储文件图片,以及读取功能。本人亲自测试、编写。值得信赖
NULL 博文链接:https://chwshuang.iteye.com/blog/2065974
NULL 博文链接:https://shift-alt-ctrl.iteye.com/blog/2195646
文件上传到MongoDBGFS和Express 使用 Express 和 Multer 编写的 MongoDB GridFS 文件服务器示例依赖关系此示例上传文件并将它们存储在 MongoDB 的 GridFS 中。 要运行此示例,您需要在系统上安装 MongoDB。 在 OSX ...
编辑配置文件gridfs-to-s3.yml以设置MongoDB GridFS / Amazon S3连接设置和其他属性。 要将文件从GridFS复制到S3 ,请运行: perl bin/copy-kvs.pl gridfs-to-s3.yml mongodb_gridfs amazon_s3 要将文件从S3复制...
java+mongDB做文件服务器,用于文件存储,写了个简单文件上传下载删除DEMO,用eclipse import项目即可。
本篇文章是对PHP操作MongoDB GridFS存储文件进行了详细的分析介绍,需要的朋友参考下
用于MongoDB GridFS的简单RESTful网关。 实现此网关的主要原因是过时的Nginx GridFS模块( )。 不幸的是,与编写用于访问GridFS的微服务相比,重新启动该项目似乎太困难了:) 安装 go install github....
骆驼:: Mongodb GridFS 该项目是Mongodb GridFS的Camel组件。 要构建此项目,请使用 mvn install 网址格式 gridfs:connectionBean?database=databaseName&bucket=bucket&operation=operationName[&moreOptions.....
收藏夹通过由 ImageMagick 和 FFMPEG 支持的 RESTful 接口公开 MongoDB GridFS ##目标创建与 Amazon S3 具有相同界面的文件存储服务,您可以将其托管在您自己的服务器中分别使用 ImageMagick 和 FFMPEG 查询图像和...
利用mongodb存储文件,前台使用百度webuploader的文件md5实现断点续传,一次上传,下次秒传,解决文件重复问题,避免数据冗余,文件上传后支持下载, 特定格式支持在线预览,office转pdf后前台新页面显示pdf,相关...