Mass storage mechanism of MONGODBMONGODB database

Source: Internet
Author: User
Tags file size md5 mongodb

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, the command line tool Mongofiles is a tool to manipulate Gridfs from the command line, such as the "testfile" file into the database, you can do the following actions. 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; chunksize:chunks size uploaddate: Storage time MD5: MD5 code length: File Size (in bytes)
Db.fs.chunks.find () parameter description:
N: The serial number representing the chunks, which starts at 0; The data field is the actual stored
To retrieve data from a database:

D:\Program files\mongodb\bin>mongofiles get test.txt
connected to:127.0.0.1 done
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:

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.