NoSql-MongoDB GridFS + ASP. net mvc implements upload and display,
The previous article introduced how to perform some simple operations on MongoDB in the dos window. However, no matter what you learn, you still need to apply it to your project,
Copy codeThe Code is as follows:// Initialize gridfs$ Conn = new Mongo (); // connect to MongoDB$ Db = $ conn-> photos; // select a database$ Grid = $ db-> getGridFS (); // get the gridfs object
// There are three methods for storing files in
Gridfs is a built-in feature of MongoDB that provides a set of file manipulation APIs to utilize MongoDB to store files, the basic principle of Gridfs is to save files in two collection, a save file index, a save file content, The contents of the
PHP operation MongoDB Gridfs storage file, tablet fileGridfs is a built-in feature of MongoDB that provides a set of file manipulation APIs to utilize MongoDB to store files, the basic principle of Gridfs is to save files in two collection, a save
Gridfs is a feature of MONGO that specializes in storing small files.Used in the following scenarios:1. Write file: Mongofiles put file path
Note which library the current MONGO instance is linked to, the GRIDFS system in which the file is
Before writing a article about Gridfs, but there is no information about the deletion of Gridfs, now make up, a bit of a sense of the title party.
1, Command mode
[root@localhost ~]# mongofiles Delete 111.jpg//delete 111.jpgConnected
Gridfs is a file specification for storing large files in MongoDB:The MongoDB database holds binary objects in support of the Bson format , but the Bson objects in MongoDB cannot exceed 4MB in maximum.The GRIDFS specification provides a transparent
The MD5 is stored in the Fs.files metadata information after uploading, which is used to verify the MD5 value after the user gets the large file.The way to view MD5 values in Linux is: md5sum file nameSo let's look at the MD5 of the get file from
Generally take the first method, directly transfer files, the second method suitable for the generation of data not saved to the local upload but directly to the binary system to MongoDB, the third way is to directly upload the form of the file into
There are two ways to store files in MongoDB in the gridfsb mode: 1. Command Line program files 2. client-side driver programming (using Java as an example)
1. Command Line Program Files
You can insert file data to the MongoDB database under the
The example of this article for everyone to share the Mongodb3.3 database for Gridfs additions and deletions, for your reference, the specific contents are as follows
The Program.cs code is as follows:
Internal class Program {private static
photos;//Select database
$grid = $db-> Getgridfs (); Get Gridfs Object
Gridfs has three ways of storing files
The first type of direct storage file
$id = $grid->storefile ("./logo.png");
Second storage file binary stream
$data = Http://www.
"Database Commands""How the Command Works"The commands in MongoDB are actually implemented as a special type of query that is executed against the $cmd collection. RunCommand simply accepts the command document and executes the equivalent query, so>
1 Installation and Configuration Nginx-gridfs
Our request to access the picture first passes through the Nginx and then through the Nginx-gridfs to MongoDB, so configuring Nginx-gridfs is an important step.
If the server does not have Nginx
GridFS introduction mongoDB documents are stored in BSON format and support binary data types. When we save binary data directly to mongoDB documents. However, when the file size is too large, the length of each file, such as the sample and video,
Fixed collection:
Property 1. Insert the fixed set very quickly
Attribute 2: Query output in the order of insertion is extremely fast
Attribute 3: Ability to retire the oldest data when inserting the latest data
Usage 1: Store log information
Usage
"Abstract" Today has entered the era of large data, especially large-scale Internet web2.0 application development and cloud computing needs of the mass storage and massive computing development, the traditional relational database can not meet this
Recently in writing a small thing, need to save some pictures, I used the FTP or direct database to save files, with FTP to save the file feel more trouble, with the database bar, but also to change the field type, modify code, modify query
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.