Search code examples
javamongodbarchitecture

Storing pictures using MongoDB


I am currently facing a challenge assigned by my superior. The task at hand involves the storage of a substantial volume of images, each approximately 10 MB in size, and the subsequent delivery of these images to clients upon request via web browsers. The preferred technological stack for this endeavor is Java in combination with MongoDB. Upon initial review, it seems that I have two primary options to consider:

Option #1: Storing the images directly in MongoDB using gridFS.

Option #2: Storing the images on a filesystem and utilizing the database to store indices and other related metadata.

I would greatly appreciate any insights or suggestions on this matter. If feasible, please also provide links to any similar projects for reference. Thank you in advance for your assistance.

Haven't tried anything yet. Just trying to figure out what is the best solution here.


Solution

  • If there is a guarantee that the size will not exceed the document maximum it's always possible to store the actual picture as a binary.

    See this thread for further reading regarding both gridFS and storing as binary:

    https://www.mongodb.com/community/forums/t/process-of-storing-images-in-mongodb/15093