Gridfs is a mechanism for storing the sophomore file in MongoDB. There are several reasons why you can use Gridfs to save files:
Gridfs can simplify requirements. If you have already used Mongodb,gridfs, you do not need a separate file storage schema.
GRIDFS leverages the established replication and fragmentation mechanisms, so it is easy to recover and extend for file storage.
Gridfs can avoid some problems with the file system that is used to store user uploaded content. For example, there is no problem with Gridfs placing a large number of files in the same directory.
Gridfs does not produce a disk because the MongoDB allocates a 2G of data file space.
using Gridfs:mongofiles
Mongofiles is a gridfs utility for managing GRIDFS files
--HELP command
[Root@racdb ~]# Mongofiles--help
Browse and modify a gridfsfilesystem.
Usage:mongofiles [Options]command [Gridfs filename]
Command
One of (List|search|put|get)
List-list all files. ' Gridfs filename ' is an optional prefix
Which listed filenames must beginwith.
Search-search all files. ' Gridfs filename ' is a substring
Which listed filenames must contain.
Put-add a file with filename ' gridfsfilename '
Get-get a file with filename ' gridfsfilename '
Delete-delete all files with filename ' gridfs filename '
Options
--help Produce HelpMessage
-V [--verbose] is more verbose (includemultiple times
Formore verbosity e.g.-vvvvv)
--version Print Theprogram ' s version and exit
-h [--host] arg MONGO host to connect to (<set
NAME>/S1,S2 for sets)
--port ARG server port. Can also use--host
Hostname:port
--ipv6 Enable Ipv6support (disabled by
Default
-U [--username] arg username
-P [--password] arg password
--authenticationdatabase arg user source (defaults to dbname)
--authenticationmechanism Arg (=MONGODB-CR)
Authentication mechanism
--dbpath arg directly accessmongod database files
In Thegiven path, instead of
Connecting to a Mongod server-needs
To lockthe Data directory, so cannot
Be usedif a mongod is currently
Accessing the same path
--directoryperdb each db are in a separate directly
(relevant only if dbpath specified)
--journal enable journaling (relevant only if
dbpathspecified)
-d [--DB] arg database to use
-c [--collection] arg collection to use (Somecommands)
-l [--local] arg local filename to Put|get (default is
To usethe same name as ' Gridfs
FileName ')
-T [--type] arg MIME type for put (Defaultis to omit)
-R [--replace] Remove other files Withsame name after
Put
--Uploading files
[root@racdb ~]# Mongofiles put Foo.log
Connected to:127.0.0.1
Added file: {_id:objectid (' 56caba480ad7ef0aa8a76f0c '), FileName: "Foo.log", chunksize:261120, Uploaddate:new Date ( 1456126536618), MD5: "D1bfff5ab0cc6b652aaf08345b19b7e6", length:21}
done!
--Listing files
[Root@racdb ~]# mongofiles List
Connected to:127.0.0.1
Install.log 54876
Foo.log 21
--Download file
[Root@racdb ~]# rm-f Foo.log
[root@racdb ~]# Mongofiles Get Foo.log
Connected to:127.0.0.1
Done Write To:foo.log
[Root@racdb ~]# ll Foo.log
-rw-r--r--. 1 root 21 February 15:36 Foo.log