Take the 2-minute tour ×

I was wondering which is better/faster:

  1. Having a separate collection of documents that just contain the image saved as binary data, and possibly some metadata.
  2. Or using GridFS to store the images.
share|improve this question

3 Answers 3

up vote 15 down vote accepted

If your images are small you can store them as binary data in the documents in your collection. Just consider that you will be retrieving them every time you query your document (unless you exclude the 'image' field from your queries).

However, if your images are larger I would use GridFS. GridFS has some features that make it very good at handling images that you should consider:

  • For larger images, when they are stored in GridFs they will be split in chunks and you can store very large files. If you try to store images in your document, you are constrained by the 16Mb max size of a document, and you are consuming space that needs to be used for your actual document.
  • You can add metadata to the image itself and run queries against these attributes, as if you were doing it from a regular document in a collection. So GridFS is as good as a document for metadata about the image.
  • I really like that I get MD5 hash calculated on the images. (It is very useful for some of my cases).
  • By storing images in GridFS you save yourself the preprocessing of the image into binary format (not a big deal, but a convenience of GridFS)

In terms of performance, reading/writing against a regular document should be no different than doing it against GridFS. I would not consider performance to be a differentiator in choosing either one.

My personal recommendation is to go with GridFS, but you need to analyze for your particular use case.

Hope this helps.

share|improve this answer

I use GridFS to store photos and documents. It's so easy and retrieving it from the collection to display or save locally is easy. You can store metadata along w/ the binary data inside the same collection. This way you don't need to create an additional collection to store them.

For example, in one of my project I store user profile photos along with usernames, file type, and date of upload.

share|improve this answer
helo @luckytaxi ,"0 down vote I use GridFS to store photos and documents. It's so easy and retrieving it from the collection to display or save locally is easy." can u explain how u do image uploading , retrieving and displaying locally? –  Pravitha V Sep 29 '12 at 9:05
Any examples of this by any chance, I am actually trying to do this exactly for user profile pictures –  Lion789 Aug 20 '13 at 4:51

GridFS is developed to handle Files in an efficient way. http://www.mongodb.org/display/DOCS/When+to+use+GridFS

Do not forget that you maybe will have to translate the data to a file and back.

But to be sure, do a performance test that takes account of your usage pattern.

share|improve this answer

Your Answer


