Detailed analysis of MongoDB's Gridfs

Source: Internet
Author: User
Tags install openssl
Gridfs Introduction

Gridfs is a MongoDB a built-in feature that can be used to store a large number of small files.

Http://www.mongodb.org/display/DOCS/GridFS

Http://www.mongodb.org/display/DOCS/GridFS+Specification


Gridfs Use

Mongodb provides a command-line toolMongofiles can handle it. Gridfs , in bin directory.

List all Files:

Mongofiles List

Upload a file:

Mongofiles put Xxx.txt

To download a file:

Mongofiles Get Xxx.txt

To find a file:

Mongofiles Search XXX// will find all file names that contain " XXX "The file

Mongofiles list XXX// all filenames are looked up to " XXX "file that is prefixed

Parameter description:

–d Specify the database, default is FS ,Mongofiles list–d Testgridfs

-u–p Specify user name, password

-H Specify host

-port Specify host Port

-C Specifies the collection name, which is the default FS

-T of the specified file MIME type, which is ignored by default

Use Mongovue to view, manage Gridfs

Mongovue Address:http://www.mongovue.com/

Mongovue is a free software, but more than the days after the function is limited. The restrictions can be lifted by removing the following registry key:

[hkey_current_user\software\classes\clsid\{b1159e65-821c3-21c5-ce21-34a484d54444}\4ff78130]

It's all right to delete the value under this item.


NGINX-GRIDFS Module installation and use

Project home: Https://github.com/mdirolf/nginx-gridfs

With Nginx-gridfs, you can directly use http to access Gridfs files in the.

1. Installation

Install various dependency packages: zlib ,Pcre , OpenSSL

In Ubuntu may be the following command:

sudo apt-get install Zlib1g-dev// seemssudo apt-get install Zlib-dev cannot be installed

sudo apt-get install libpcre3 Libpcre3-dev

sudo apt-get install OpenSSL Libssl-dev

Installation git (slightly)

Use git DownloadNginx-gridfs's Code:

git clone git://github.com/mdirolf/nginx-gridfs.git

CD Nginx-gridfs

Git submodule init

git submodule update


Download Nginx :

wget Http://nginx.org/download/nginx-1.0.12.zip

Tar zxvf nginx-1.0.12.zip

CD nginx-1.0.12

./configure--add-module= The path >

Make

sudo make install

If a compilation error occurs, the Configure when addedThe--with-cc-opt=-wno-error parameter.


2. Configuration Nginx

In Server in the configuration, add the following

location/pics/{

Gridfs Pics

Field=filename

type=string;

MONGO 127.0.0.1:27017;

}

The above configuration indicates:

Database is Pics , by file name filename to access the file, filename is of type string

Currently only supported through ID and the filename to access the file.

Start Nginx : /usr/local/nginx/sbin/nginx

Use Mongovue put a picture 001.jpg uploaded to Pics the database.

Open: Http://localhost/pics/001.jpg

If successful, you can see the picture displayed.


note Item

1. Gridfs do not automatically process MD5 the same file, for MD5 , if you want to gridfs , which you want the user to self-process. The calculation of the Md5 value is done by the client.

2. Because gridfs saves file data to fs.chunks When uploading a file, and then saves the file information to fs.files , so if you fail to upload the file, it is possible that the Garbage data appears in fs.chunks . This junk data can be cleaned up regularly.


Above describes the Gridfs detailed analysis of MongoDB, including the aspects of the content, I hope to be interested in PHP tutorial friends helpful.

  • 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.