0
我正在关注simple tutorial。猫鼬等同于mongoDB查询
事情是,我正在使用momngoose而不是Mongo。 我没有问题,直到我得到了这一点:
app.get('/', (req, res) => {
db.collection('quotes').find().toArray((err, result) => {
if (err) return console.log(err)
// renders index.ejs
res.render('index.ejs', {quotes: result})
})
})
这样,报价可以访问和现在index.ejs
操纵,我试着这样做:
app.get('/theroute', (req, res) => {
MyMongoModel.find()
.then(documents => {
res.render('index.ejs', *not entirely sure on what to put here*)
})
});
但是当我试图使用index.ejs页面上的文档时,我得到了“未定义”的结果。
就是这样。不知道如何谷歌这或我该怎么做。
谢谢!
您可能需要将您想要查找的内容传递给find()方法 – heyitsjhu