"MongoDB Learning Note 29" MongoDB Gridfs Storage in depth

Source: Internet
Author: User
Tags findone md5 unique id

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.