Gridfs is a mechanism for storing a binary file in MongoDB, using Gridfs for the following reasons:
1, storage of huge files (video pictures).
2, the use of Gridfs can simplify the demand.
3, GRIDFS using the already established replication and fragmentation mechanism, fault recovery and expansion are very easy.
4, Gridfs can avoid users to upload files system problems.
5, do not produce this piece of debris.
Summary: Gridfs uses two tables to store data: Files contains metadata objects, and chunks contains some other related binary blocks.
In order for multiple grdifs to be named a single database file with a block with a prefix, the default is FS, which contains Fs.files and fs.chunks. Various other third-party languages can change the prefix.
Introduction to use: directory containing mongofile files into the bin
For example:
/usr/local/mongodb/mongofiles put'/home/timeless/Desktop/More than 2000 domain names'-U Root-penter password:connected to:127.0.0.1added file: {_id:objectid ('550d5ae73c11b4f50c88c99e'), FileName:"/home/timeless/Desktop/More than 2000 domain names", ChunkSize:261120, Uploaddate:NewDate (1426938599982), MD5:"025141eb3b856cb1d05f51c8b1fac3ec", Length: +}done!
Login MONGO >/usr/local/mongodb/mongo-uroot-pmongodb Shell version:2.6.6Enter password:connecting to:test>Show Collectionsfs.chunksfs.filespersonstockssystem.indexes>Db.fs.files.find () {"_id": ObjectId ("550d5ae73c11b4f50c88c99e"),"filename":"/home/timeless/Desktop/More than 2000 domain names","chunkSize":261120,"uploaddate": Isodate ("2015-03-21t11:49:59.982z"),"MD5":"025141eb3b856cb1d05f51c8b1fac3ec","length": + }>Db.fs.chunks.find () {"_id": ObjectId ("550d5ae7e67b9f05743cdc35"),"files_id": ObjectId ("550d5ae73c11b4f50c88c99e"),"N":0,"Data": Bindata (0,"d2hvaxmgchjpdmfjesbwcm90zwn0aw9uihnlcnzpy2ugynkgdmfsdwutzg9tywluicagioazqowgjos6ugo=") }>
List the current file information
[Email protected]:~$/usr/local/mongodb/mongofiles list -u root-127.0. 0.1/home/timeless/Desktop/More than 2000 domain name [email protected]
Download the current file
get /home/timeless/desktop/More than 2000 domain name -u root-127.0. 0.1/home/timeless/Desktop/more than 2000 domain names
Delete the specified file
[Email protected]:~$/usr/local/mongodb/mongofiles Delete /home/timeless/desktop/More than 2000 domain -u root- 127.0. 0.1 Done! [email protected]-hp-pavilion-g4-notebook-pc:~$
Mongodb-gridfs Large File system