How save and query in binary data like images in mongodb with mongoose.js driver and express.js? How save and query in binary data like images in mongodb with mongoose.js driver and express.js? express express

How save and query in binary data like images in mongodb with mongoose.js driver and express.js?


You should be using GridFS to save your file and then have a separate endpoint for the file. On your page render, you should generate a url that gets that file.

On upload I highly suggest to stream the file directory from the request to the database and on download, stream back directly to the response.

There's some modules that help you with this. express-file-store looks like a good implementation. Since it supports multiple backends, you can change it depending on the configuration(use filesystem on developement and gridfs on production, and easily change it to S3 if by any chance decided to change the backend).