The principle of gridfs is to divide large files into larger chunks and store each block as a separate document.
(1) The blocks in the Gridfs are stored in a dedicated set, the default is fs.chunks;
(2) In addition to storing each block of a file separately, the meta-information of each file block is placed in a document store, and the documents are set by default in the Fs.files collection;
For example, add the Foo.txt document to the database foo:
[Email protected] ~]# echo "Hello World" >foo.txt [[email protected] ~]# mongofiles-d foo put foo.txt connected to:127.0.0.1 added file: {_id:objectid (' 54b3d62983047a88669bc529 '), FileName: "Foo.txt", chunksize:261120, Uploadda Te:new Date (1421071914003), MD5: "6F5902AC237024BDD0C176CB93063DC4", length:12} done!
To view the appropriate collection:
> Show Collections fs.chunks fs.files system.indexes >
查看这个文档:
[[email protected] ~]# MONGO foo MongoDB shell version:2.6.6 connecting To:foo > Db.fs.chunks.findOne () { "_id": ObjectId ("54b51dc15caeb0e1a8722e8d"), "files_id": ObjectId ("54b51dc0c3ab6ae7c08f6028"), "n" : 0, "Data": Bindata (0, "Agvsbg8gd29ybgqk")} >
FILES_ID: meta-information of the file to which the block belongs;
N: The relative position of the block in the file;
Data: The binaries contained in the block;
> Db.fs.files.findOne () {"_id": ObjectId ("54b51dc0c3ab6ae7c08f6028"), "filename": "Foo.txt", "ChunkSize": 261120, "uploaddate": Isodate ("2015-01-13t13:29:37.525z"), "MD5": "6F5902AC237024BDD0C176CB9 3063dc4 "," Length ": >
_ID: The unique ID of the file, consistent with the value of files_id in each block of the file;
Length: The number of bytes contained in the file;
ChunkSize: The size of each block that makes up the file, in bytes;
Updatedate: The time when the file was uploaded to Gridfs;
MD5: The MD5 value of the file, calculated by the server;
This article is from the "Margin with Wish" blog, please be sure to keep this source http://281816327.blog.51cto.com/907015/1603698
"MongoDB Learning Note 29" MongoDB Gridfs Storage in depth