I. Overview
Gridfs is a storage mechanism for MongoDB that is used to store large binary files.
Advantages:
1. Using Gridfs can simplify your stack. If you are already using MongoDB, you can use GRIDFS instead of a standalone file storage tool
2.GridFS automatically balances existing replications or automatic shards set for MongoDB, so it is easier to fail over or scale out the file store.
3. When used to store user uploaded files, Gridfs can resolve some other file system problems that may be encountered in a more leisurely manner.
4. In Gridfs, the concentration of file storage is very high, because MongoDB allocates data files in 2G units.
disadvantage:
1.GridFS performance is relatively low: Access files from MongoDB, Rather than accessing files directly from the file system
2. If you want to modify the document on the Gridfs, you can only delete the existing file, The entire document is then re-saved.
The
simplest way to use the GRIDFS is to use the Mongofiles tool, which is included in all MONGO DB distributions, and can be used to upload files, download files, view file lists, search for files, and delete files in Gridfs. Here's a demonstration for you.
second, the code demonstration.
2.1 Uploading a file
mongofiles-d foobar-l "E:\a.txt" put "a.txt"
2.2 Viewing a list of files
Db.fs.chunks.find () and Db.fs.files.find () store all file information for the file system
2.3 View All Files
mongofiles-d foobar List
2.4 Deleting a file that exists
mongofiles-d foobar Delete ' a.txt '
third, summary.
The
Gridfs system provides a very efficient system for us to store very large data files in MongoDB
.
Java from getting started to mastering--database article MONGO db Gridfs file system