Store image in mongodb


In the process of creating a small webservice with mongodb, I had one question about images.
For example I want to store maximum 6 images per document (something as below)

    "_id": "<ObjectId>",
    "deviceId" : "<String>",
    "schema_version": "<Int>",
    "firstname": "<String>",
    "birthdate": "<ISODate>",
    "inscriptionDate": "<ISODate>",
    "lastConnectionDate": "<ISODate>",
    "photos": []

If I put a max size per image of 5Mb for example, if one user puts 6 images, this document will be over the limit of 16Mb.

Should I use GridFS even if the image I store are lesser than 16Mb ?
I’m also thinking of storing the image on Google Storage or AWS Cloud, and just put the URLS in the array. Which way would you recommend ? GridFS or distant storage ?

Hey @Yoni_40785

They way that I have done this is to store the images in a AWS S3 bucket with CloudFront serving the S3 content ( this way I can restrict access to the content ). I store the name of the image in MongoDB and use that to query AWS S3.

Here are some CF templates to help
Anything I launch an AWS I use a Cloud Formation template to help keep track of what services I am using.


I’d lean towards S3/Google Cloud Storage as well from a cost + flexibility point of view. And I would imagine S3/Google Storage would outperform GridFS. But I wonder if someone has done some file retrieval benchmarking between the two (GridFS vs S3/Google Storage)?

Yeah that was I was thinking as well, the scalability of S3 and Google Storage is a huge bonus and there is no need to save all the image which could fill the mongo server quite quickly.