Java: Getting started to mastering-Database: Mongo DB GridFS file system, mongogridfs

Source: Internet
Author: User

Java: Getting started to mastering-Database: Mongo DB GridFS file system, mongogridfs

I. Overview
GridFS is a storage mechanism of MongoDB used to store large binary files.
Advantages:
1. Using GridFS can simplify your stack. If you are using MongoDB, you can use GridFS instead of an independent file storage tool.
2. GridFS automatically balances existing copies or sets automatic shards for MongoDB. Therefore, it is easier to perform failover or horizontal scaling for file storage.
3. When used to store files uploaded by users, GridFS can easily solve problems that may occur in other file systems.
4. In GridFS, the concentration of file storage is very high, because MongoDB allocates data files in 2 GB.
Disadvantages:
1. GridFS performance is relatively low: Accessing files from MongoDB is not as fast as accessing files directly from the file system
2. If you want to modify a document on GridFS, you can only Delete the existing file and save the entire document again.
The simplest way to use GridFS is to use the program files tool. All Mongo DB distributions contain program files, you can use it to upload, download, view, search, and delete objects in GridFS. The following is an example.
Ii. Code demonstration.
2.1 upload a file
Program Files-d foobar-l "E: \ a.txt" put "a.txt"
2.2 view the file list
Db. fs. chunks. find () and db. fs. files. find () store all file information of the file system.
2.3 view all files
Program Files-d foobar list
2.4 delete an existing file
Program Files-d foobar delete 'a.txt'
Iii. Summary.
The GridFS system provides an efficient system for us to store large data files with MongoDB.

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.