I'm trying to upload and view files from MongoDB but while accessing files from MongoDB using GridFS raising an error "TypeError: Cannot read property 'files' of undefined". Anyone, please help me to figure out this error.
let gfs;
conn.once('open', function () {
var gfs = Grid(conn.db, mongoose.mongo);
gfs.collection('uploads');
});
app.get('/files',(req,res)=>{
gfs.files.find().toArray((err,files)=>{
if (err) return res.status(400).json({err});
return res.json(files);
}
)
});