How to store files of varying size ( 1mb to 30mb) in MongoDB ?

96 views
Skip to first unread message

Devender Yadav

unread,
Apr 2, 2015, 10:55:26 AM4/2/15
to mongod...@googlegroups.com

I am using Mongo-Java Driver 2.13. I want to store pdf Files of varying size ( 1mb to 30mb).

Note: I know I can't store a document having size greater than 16mb in MongoDB. Then, I need to use GridFS. Also, I need to get whole pdf at a time not chunks.

I want to save pdf Files of small size(<16 mb) in  a collection (say BookPdf) in normal way. For larger files, I need to store it using GridFS(in fs.chunks and fs.files). When I want to retrieve all pdf Files, it need to access BookPdf collection and fs.chunks, fs.files collections. It will loose atomicity for that find operation and also, it will take much time to get data from different collections.

What should be the best way:

  • Save all of my data in GridFS.

  • Save data in different collections according to size.

  • Any other approach?

Thanks in advance,

Devender

Will Berkeley

unread,
Apr 2, 2015, 12:00:08 PM4/2/15
to mongod...@googlegroups.com
  • Save all of my data in GridFS.

Do this. Given that you must use GridFS because you have some files larger than 16MB and must retrieve all files regardless of size / storage method, you might as well keep your life simple and rely totally on GridFS since you won't have any more guarantees in terms of atomicity than what you get from GridFS.

-Will 
Reply all
Reply to author
Forward
0 new messages