MongoDB Series Tutorial (eight): Gridfs storage

Source: Internet
Author: User
Tags comparison table install mongodb

MongoDB Series Tutorial (eight): Gridfs storage

Gridfs Introduction

MongoDB documents are stored in Bson format and support binary data types when we store binary format data directly into MongoDB's documentation. However, when files are too large, such as samples and videos, each document is limited in length, so MongoDB provides a canonical--gridfs for handling large files.

Gridfs Implementation principle

In the Gridfs database, by default, Fs.chunks and Fs.files are used to store the file, where the Fs.files collection holds the file's information, fs.chunks the data that holds the file, One of the records in a Fs.files collection is as follows: A file information is shown below.

{"_id": ObjectId ("4f4608844f9b855c6c35e298"),//unique ID, can be a user-defined type "filename": "CPU.txt",//FileName "Length": 778,//File Length "chunkSize": 262144,//chunk size "uploaddate": Isodate ("2012-02-23t09:36:04.593z"),//upload time "MD5" : "E2c789b036cfb3b848ae39a24e795ca6",//MD5 value "ContentType": "Text/plain"//file MIME type "meta": null//File Other information, the default is no "meta" this key, the user can define themselves as any Bson object}


Corresponding to the chunk in fs.chunks (Chinese meaning data block), as follows:

{"_id": ObjectId ("4f4608844f9b855c6c35e299"),//chunk id "files_id": ObjectId ("4f4608844f9b855c6c35e298"),//File The ID, corresponding to the object in the Fs.files, corresponds to the foreign key "n" of the Fs.files collection: 0,//The number of chunk blocks of the file, if the file is greater than chunksize, it will be split into multiple chunk blocks "data": Bindata (0, "QGV".     .") The binary data of the file, the specific content is omitted here}


The default size is 256k, so the file into the GRIDFS process, if the file is larger than chunksize, then the file is divided into multiple chunk, then the chunk saved in Fs.chunks, and finally the file information into Fs.files.

When reading the file, according to the conditions of the query, find a suitable record in the Fs.files, get the value of "_id", and then find all files_id _id chunk according to this value to Fs.funks, and sort by "n", and then read the chunk in sequence. The contents of the data object and revert to the original file.

Note:

1, Gridfs does not automatically process MD5 the same file, for MD5 the same file, if you want to have only one store in Gridfs, to user processing, the calculation of MD5 value is done by the client.

2, because Gridfs in the process of uploading files is the first to save the file data to Fs.chunks, and finally save the file information to Fs.files, so if the upload file process failure, there may be garbage data in the fs.chunks, these garbage data, can be cleaned up regularly.  

Reference Source:
MongoDB Series Tutorial (eight): Gridfs storage
Http://www.lai18.com/content/409594.html

Extended Reading

"MongoDB Technical Knowledge" series of technical articles organized collection  

Basics to get started with 1mongoDB

2MongoDB Getting Started Tutorials (includes installation, common commands, related concepts, tips, common actions, etc.)

3MongoDB Getting Started Tutorial Shard Technology detailed

4MongoDB Introductory tutorials Common operations and Maintenance technology introduction

Example of C # driver operation in 5MongoDB Starter Tutorial

6MongoDB Introductory Tutorial Master-slave replication configuration detailed

Introduction to the aggregation and cursor operations of the 7MongoDB Getting Started tutorial

8MongoDB Getting Started teaching the operation of adding and deleting MongoDB database

An analysis of index operation of 9MongoDB Getting Started tutorial

10MongoDB Getting Started tutorial of the MongoDB database installation diagram under Windows

11MongoDB query field does not create an index caused by Connection Timeout exception solution case sharing

12MongoDB log file is too large a workaround

13MongoDB Community Edition and Enterprise Edition difference comparison table

14MongoDB Chinese Community Initiator takes you to learn MongoDB.

Analysis on performance bottleneck of 15 MongoDB database

The method and performance of 16MongoDB paging query

Cluster architecture implementation of 17MongoDB Shard storage

18Mongodb Bulk deletion of Gridfs file instances

19Mongodb adding, removing Shard server instances

20Mongodb adding, removing Arbiter node instances

MongoDB Installation and configuration tutorial under 21CentOS system

22MongoDB Modifying and deleting a document's Domain property instance

MongoDB basic operations in 23Python: connecting, querying instances

24MongoDB Export Query Results to file example

Things to keep in mind when creating indexes in 25MongoDB

Some pits in 26MongoDB (best not to use)

27 adding user rights to MongoDB sharing method

Simple installation and basic operation of MongoDB under 28Linux system

Basic management commands for the 29MongoDB tutorial

Aggregation of 30MongoDB Tutorials (count, distinct, and group)

Introduction to the index of 31MongoDB tutorials

Data manipulation examples of 32MongoDB tutorials

Basics of getting Started with 33MongoDB tutorials

Examples of query operations for 34MongoDB tutorials

35MongoDB Series Tutorial (iv): Set User access rights

36MongoDB Series Tutorial (eight): Gridfs storage

Introduction to features and advantages of 37MongoDB database

38MongoDB about MongoDB Five features

39MongoDB Series Tutorial (vi): Java operation MongoDB Instance

40MongoDB Series Tutorial (vii): A detailed description of the MONGODB data structure

41MongoDB Series Tutorial (v): MONGO Grammar and MySQL syntax comparison learning

42MongoDB Series Tutorial (ii): About MongoDB

43MongoDB Series Tutorial (i): NoSQL origins

Introduction to MapReduce in 44MongoDB

45MongoDB Series Tutorial (iii): Download and install MongoDB in Windows

46 on how to back up MongoDB

47MongoDB Common Command Summary

48MongoDB and MySQL operation comparison table and the difference introduction

49MongoDB Security Configuration Detailed

Bson Introduction and usage examples in 50MongoDB

MongoDB Series Tutorial (eight): Gridfs storage

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.