The massive storage mechanism of "MongoDB" MongoDB database

Source: Internet
Author: User
Tags md5

Gridfs is a file specification that stores large files in a MongoDB database.

first, how to achieve mass storage

Because the size of the Bson object in MongoDB is limited, the GRIDFS specification provides a transparent mechanism for dividing a large file into smaller files. Such a mechanism allows for the effective preservation of large files of objects, especially which are huge files, such as video, high-definition images; The specification specifies a standard for chunking files, each of which holds a metadata object in the collection object, and one or more block objects can be combined in a chunk block collection. MongoDB mainly uses the Mongofiles tool.

Grifs uses two tables to store data:

Files (containing metadata objects)

Chunks (a binary block that holds you some pertinent information)

To name multiple Gridfs as a single database, both the file and the block have a prefix. By default, the prefix is fs. So any default Gridfs storage will include namespaces Fs.files and Fs.chunks.

Second, command-line toolsMongofiles is a tool for manipulating Gridfs from the command line, such as the file "Testfile" in the database, which can be done as follows. First of all, let's meet Mongofiles in general:

instance to store files in the database


db.fs.files.find () parameter description:
FileName: The name of the stored file;size of the Chunksize:chunksuploaddate: Storage TimeMD5: MD5 code of the fileLength: Size of file (in bytes)
Db.fs.chunks.find () parameter description:
N: The serial number representing the chunks, which starts from 0;The data field is actually stored
to retrieve data from a database:
D:\Program files\mongodb\bin>mongofiles Get test.txtconnected to:127.0.0.1done write To:test.txt

Gridfs files can also be indexed, and a block can be retrieved using the values of its file_id and N.

db.fs.files.find () parameter description:

The massive storage mechanism of "MongoDB" MongoDB database

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.