Retrieve image from mongoDB Retrieve image from mongoDB mongoose mongoose

Retrieve image from mongoDB


First, have a look at the GridStore documentation. There are two ways to approach this:

One is to call gridStore.read() inside your gridStore.open() function. You can send the data from callback to the response.

gridStore.read(function(err, data) {    res.write(data);    res.end();});

The data parameter in the callback will contain your file.

Another option is to use gridStore.stream() and pipe the stream to the response.

gridStore.stream().pipe(res);