I'm new to mongodb. I wanted to know if I initially code my app using mongodb and later I want to switch to mongodb gridfs, will the switching (of a filled large database) be possible.
So, if I am using mongo db initially and after some time of running the app the database documents exceed the size of 16Mb, I guess I will have to switch to gridfs. I want to know how easy or difficult will it be to switch to gridfs and whether that will be possible?
Thanks.
GridFS is used to store large files. It internally divides data in chunks(By default 255 KB). Let me give you an example of saving a pdf file in MongoDB using both ways. I am assuming the size of pdf as 10 MB so that we can see both normal way and GridFS way.
Normal Way:
Say you want to store it in
normal_book
collection intestDB
database. So, whole pdf is stored in this collection and when you want to fetch it usingdb.normal_book.find()
, whole pdf will be fetched in memory.GridFS way:
In GridFS, we have two collections, one is for storing data and other is for storing its metadata. It will store data in
fs.chunks
collection and metadata infs.files
collection. Now, the beauty of GridFS is that you can find the whole file at once or you can find chunks individually.