MongoDB study notes (5) MongoDB file access operation
Because the document structure of MongoDB is BJSON format (BJSON full name: Binary JSON), and BJSON format itself supports saving data in binary format, so you can put The data in the binary format of the file is saved directly into the MongoDB document structure. However, since the maximum length of a BJSON cannot exceed 4M, the maximum file that can be stored in a single document cannot exceed 4M. In order to provide support for large-capacity file access, the samus driver provides “GridFS” mode to support, and “GridFS” mode file operations need to introduce a new assembly “MongoDB.GridFS.dll”. Below we implement it in two ways. 1. Access files in the document object When the file size is small, it is simpler to implement directly into the document object. For example, the access of a large number of picture files, etc., the general picture files will not exceed 4M. Let’s implement an example of uploading pictures and storing them in the database, and then taking them out and writing them back to the page: 1. Save the picture in BJSON /// /// Save the picture in BJSON /// public void SaveImgBJSON(byte[] byteImg) { Document doc = new Document(); doc[“ID”]…