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: