Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing Images: MongoDb vs File System

I need to store a large number of images (from around 10,000 images per day) With an average size of around 1 to 10 MB for each image.

I can store these images in MongoDB using the GridFS Library or by just storing the Base64 conversion as a string.

My question is that, is MongoDB suitable for such a payload or is it better to use a file system?

Many Thanks,

like image 832
DafaDil Avatar asked May 09 '13 13:05

DafaDil


People also ask

Is storing images in MongoDB a good idea?

Storing images is not a good idea in any DB, because: read/write to a DB is always slower than a filesystem. your DB backups grow to be huge and more time consuming. access to the files now requires going through your app and DB layers.

Is it better to store images in database or filesystem?

Generally databases are best for data and the file system is best for files. It depends what you're planning to do with the image though. If you're storing images for a web page then it's best to store them as a file on the server. The web server will very quickly find an image file and send it to a visitor.

Which database is best for storing images?

The large images should be stored in something like AWS S3, HDFS, a Content Delivery Network (CDN), a web server, file server or whatever else would be great a serving up large static objects, in accordance with your use case and budget.

Can we store images in MongoDB?

So for storing an image in MongoDB, we need to create a schema with mongoose. For that create the file `model. js` file and define the schema. The important point here is that our data type for the image is a Buffer which allows us to store our image as data in the form of arrays.


1 Answers

MongoDB GridFS has a lot of advantages over a normal file system and it is definitely able to cope with the amount of data you are describing as you can scale out with a sharded mongo cluster. I have not saved that much binary data in it on my own but I do not think there is a real difference between the binary data and text. So: yes, it is suitable for the payload.

like image 149
Fabian Avatar answered Oct 04 '22 04:10

Fabian