//add var
let gridFSBucket;
let gfs;
connection.once('open', () => {
gfs = Grid(conn.db, mongoose.mongo);
// add value to new var
gridFSBucket = new mongoose.mongo.GridFSBucket(conn.db, {
bucketName: 'user_images'
});
gfs = Grid(connection.db, mongoose.mongo);
gfs.collection(image_bucket_name);
if (file.contentType === 'image/jpeg' || file.contentType === 'image/png') {
//now instead of const readstream = gfs.createReadStream(file.filename);
//add this line
const readStream = gridFSBucket.openDownloadStream(file._id);
readSteam.pipe(res);
}
});