我是编程的新手。我的本地数据库中有一个名为“Practice”的集合,其中包含“名称、角色、组织”。我想弄清楚如何使用猫鼬在 .ejs 文件中打印此信息。
在我的 server.js 中,我有
require('./app/routes.js')(app, passport);
mongoose.connect(configDB.url); // connect to our database
var schema = mongoose.Schema;
mongoose.model('practice', new schema({ Name: String, Role: String, Org: String}),'practice');
var practice = mongoose.model('practice');
practice.find({}, function(err, data) { console.log(err, data); });
Run Code Online (Sandbox Code Playgroud)
在路线中,
app.get('/profileface', isLoggedIn, function(req, res) {
res.render('profileface.ejs', {
user : req.user
});
});
Run Code Online (Sandbox Code Playgroud)
在视图文件夹中的文件 profileface.ejs 中,我有以下内容可以打印我的“练习”集合中的名称。
<%= practice.name %>
Run Code Online (Sandbox Code Playgroud)
虽然它在控制台中打印,但当我尝试访问 profileface.ejs 时,出现以下错误。
ReferenceError: C:\Users\SEESCHU\Desktop\Linneus university\Assignments\302\Assignment 2\code\Test3\views\profileface.ejs:36 34| </div> 35| >> 36| <%= practice.name %> 37| 38| <!-- <div class="text-center"> 39| <p>Assignment for …Run Code Online (Sandbox Code Playgroud)