[MongoDB] massive storage mechanism of MongoDB database, massive storage of mongodb
GridFS is a file specification that stores large files in Mongodb databases.
I. How to implement massive storage
Because the size of bson objects in Mongodb is limited, the gridfs specification provides a transparent mechanism to split a large file into multiple smaller files. This mechanism allows you to effectively store objects of large files, especially those large files, such as videos and high-definition images. This specification specifies a standard for splitting files, each file stores a metadata object in the collection object. One or more block objects can be combined in a chunk collection. Mongodb mainly uses the program files tool.
Grifs uses two tables to store data:
Files (including metadata objects)
Chunks)
To name multiple gridfs as a single database, files and blocks have a prefix. By default, the prefix is fs. Therefore, any default gridfs storage will include the namespace fs. files and fs. chunks.
2. the command line tool program files is a tool used to operate gridfs from the command line. For example, you can save the "testfile" file to the database and perform the following operations. First, let's take a look at program files:
The instance stores files in the database.
Description of db. fs. files. find () parameters:
Filename: name of the storage file; chunksize: chunks size uploaddate: storage time md5: file md5 code length: file size (unit: bytes)
Db. fs. chunks. find () parameter description:
N: indicates the chunks sequence number, which starts from 0. The data field is the actually stored data.
Extract data from the database:
D:\Program Files\mongodb\bin>mongofiles get test.txtconnected to: 127.0.0.1done write to: test.txt
The gridfs file can also create an index, and a block can use its file_id and n values for retrieval.
Description of db. fs. files. find () parameters: