I need to add images to my mongoDB using Node and Express. I am able to normal data in it by running the mongo shell. But I cannot find any method to add images to it. Can anybody help?
Asked
Active
Viewed 1,476 times
4
-
4Take a look at GridFS https://docs.mongodb.com/manual/core/gridfs/ – George Chen Aug 03 '16 at 17:07
1 Answers
6
Please don't do this. Databases are not particularly well suited to storing large bits of data like images, files, etc.
Instead: you should store your images in a dedicated static file store like Amazon S3, then store a LINK to that image in your MongoDB record.
This is a lot better in terms of general performance and function because:
- It will reduce your database hosting costs (it is cheaper to store large files in S3 or other file services than in a database).
- It will improve database query performance: DBs are fast at querying small pieces of data, but bad at returning large volumes of data (like files).
- It will make your site or application much faster: instead of needing to query the DB for your image when you need it, you can simply output the image link and it will be rendered immediately.
Overall: it is a much better / safer / faster strategy.

rdegges
- 32,786
- 20
- 85
- 109