GridFS is a specification for storing and retrieving files that exceed the BSON-document size limit of 16 MB. Instead of storing a file in a single document, GridFS divides the file into chunks.
MongoDB GridFS
Store and retrieve files exceeding the 16MB BSON document limit.
Key Takeaways: MongoDB GridFS
Mastering MongoDB GridFS helps you write clean and reliable MongoDB code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
MongoDB GridFS Code Example
MongoDB// Using GridFSBucket in Node.js
const bucket = new mongodb.GridFSBucket(db, { bucketName: "resumes" });
// fs.createReadStream("resume.pdf").pipe(bucket.openUploadStream("resume.pdf"));
Output
Streams large media/documents into 255KB chunks in chunks collection
Run this example on your own computer. The "Get Started" lesson shows how to set it up.
Finished this lesson?
Mark it complete to track your progress.
Stuck on something?
Ask the community in the CodesInTech forum.
Need a developer?
Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.
Explore Our Services