Careeroza
GridFS
๐น What is GridFS?
GridFS is a system used to store large files in MongoDB.
MongoDB has a limit of 16MB per document
GridFS helps store files larger than 16MB
Simple:
Big file โ split into small chunks โ store in DB
๐น How GridFS Works
- File is divided into small chunks (usually 255KB)
- Stored in two collections:
- files collection โ stores file info (name, size, type)
- chunks collection โ stores actual file data
๐น Example Idea
Uploading a video file:
-
Metadata โ stored in
fs.files -
Binary chunks โ stored in
fs.chunks
๐น Why Use GridFS?
- Store large files (videos, images, PDFs)
- Stream files efficiently
- Avoid file system dependency
- ๐น When to Use GridFS
Use when:
- File size > 16MB
- Need to store files inside database
- Need streaming support
๐น When NOT to Use
- Small files (normal storage is enough)
- Better to use cloud storage (like AWS S3) in many cases
Simple Understanding
- GridFS = file storage system in MongoDB
- Splits large files into chunks