我的页面上出现此错误。关于这个概率的任何想法。无论我在这里惰性而不是文件我都遇到相同的错误。
gfs.collection('wdress')。findOne({文件名:img},(错误,文件)=> {<-185 代码
然后我得到了:TypeError:无法读取未定义的属性'collection'
// connection
let gfs;
const Mongo = 'mongodb://localhost/milenz';
var conn = mongoose.createConnection(Mongo,{ useNewUrlParser: true});
conn.once('open',() => {
// Init Stream
gfs = Grid(conn.db, mongoose.mongo);
gfs.collection('wdress');
});
router.get('/:filename', (req,res) => {
const img = req.params.filename; // Filename
gfs.files.findOne({filename: img},(error,file) =>{ <-- 185 code
// Add Recent View :
if(error) {
console.error('There was an error', error);
}
//错误
TypeError: Cannot read property 'files' of undefined
at router.get (M:\FinalProject\Commerce\routes\index.js:185:7)