GridFS — MongoDB Technical Interview Questions & Answers
Storing large files that exceed the 16MB document limit.
GridFS
- Simple meaning: GridFS splits files larger than 16MB into chunks stored as documents (fs.files + fs.chunks).
- How to use: GridFS APIs in drivers for videos/PDFs. Prefer object storage (S3) for most new apps; know GridFS for interviews.
- Common mistake: stuffing a 50MB video into one document — 16MB cap.
- Interview tip: “16MB document limit → GridFS chunks. Or store files outside Mongo.”
Technical Interview Tip: 16MB cap is the reason GridFS exists.
Code Examples for GridFS
GridFS — working example
// GridFS splits large files across fs.files + fs.chunks (shell helpers / mongofiles / drivers)
db.fs.files.findOne({ filename: "resume.pdf" })
db.fs.chunks.find({ files_id: ObjectId("507f1f77bcf86cd799439011") }).sort({ n: 1 })GridFS stores files larger than the 16MB BSON limit as chunked documents.
How to Explain GridFS to an Interviewer
When GridFS?
When a file cannot fit in one 16MB document