我有以下代码。
events.js模型
const mongoose = require('mongoose');
const locationSchema = mongoose.Schema({
_id: mongoose.Schema.Types.ObjectId,
eventType: String,
attendees: { type: Number, default: 0 }
})
module.exports = mongoose.model('events', locationSchema)
index.js路由
const express = require('express');
const router = express.Router();
const ctrlMain = require('../controllers/main');
const mongojs = require('mongojs');
const mongoose = require('mongoose');
const Event = require('../models/events')
mongoose.connect('mongodb+srv://*****:*****@cluster0-myta3.mongodb.net/newintown?retryWrites=true&w=majority')
// get all events
router.get('/eventList', ctrlMain.eventList)
我的控制器中有以下物品
//事件列表
const eventList = (req, res, next) => {
Event.find()
.exec()
.then(doc => {
console.log(doc);
res.render('eventList', {
title: 'New In Town',
events: doc
})
})
.catch(err => console.log(err))
}
集合中的所有内容都记录到控制台中,确定,因此查询有效,但是我正努力将其纳入PUG模板。我的模板看起来像这样
block content
each event in events
p.mainText = event.eventType
问题是它只写了'event.eventType'一词。如何显示查询中的eventType字段?