MongoDB Advanced (GRIDFS)

Source: Internet
Author: User
Tags mongodb server port


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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.