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