Wednesday, October 12, 2022

Mongo GridFS Storage

GridFS is the MongoDB specification for storing and retrieving large files such as images, audio files, video files, etc. It is kind of a file system to store files but its data is stored within MongoDB collections. GridFS has the capability to store files even greater than its document size limit of 16MB.


GridFS divides a file into chunks and stores each chunk of data in a separate document, each of maximum size 255k.


GridFS by default uses two collections fs.files and fs.chunks to store the file's metadata and the chunks. Each chunk is identified by its unique _id ObjectId field. The fs.files serves as a parent document. The files_id field in the fs.chunks document links the chunk to its parent.


Following is a sample document of fs.files collection −


Following is a sample document of fs.files collection −

{

   "filename": "test.txt",

   "chunkSize": NumberInt(261120),

   "uploadDate": ISODate("2014-04-13T11:32:33.557Z"),

   "md5": "7b762939321e146569b07f72c62cca4f",

   "length": NumberInt(646)

}

Following is a sample document of fs.chunks document −

{

   "files_id": ObjectId("534a75d19f54bfec8a2fe44b"),

   "n": NumberInt(0),

   "data": "Mongo Binary Data"

}

references:

https://www.tutorialspoint.com/mongodb/mongodb_gridfs.htm#:~:text=GridFS%20is%20the%20MongoDB%20specification,document%20size%20limit%20of%2016MB.


No comments:

Post a Comment