javascript - 猫鼬种群不存在
问题描述
人口没有在下面的代码中工作..我该怎么办?我想用他的参展商填充这个“摊位”模型。(参展商编号)。
这是模型
const stall = new mongoose.Schema({
name:{
type:String,
default:'Stall Name'
},
description:{
type:String,
default:'Stall Description'
},
logoImage:{
type:String,
default:'/public/images/logoImage.jpg'
},
exhibitorID:{
type:mongoose.Schema.Types.ObjectId,
ref:'Exhibitor'
},
eventID:{
type:mongoose.Schema.Types.ObjectId,
ref:'Event'
}
})
module.exports = mongoose.model('Stall',stall)
这是路线
router.get('/all/:eventID',eventAdminAuth,async(req,res)=>{
try{
var ob = await event.findById(req.params.eventID)
var stalls = await stall.find({eventID:req.params.eventID}).populate('Exhibitor')
console.log(stalls)
if(ob){
res.locals.event=ob
res.render('eventSettings/stalls',{stalls:stalls})
}else{
res.send('no event')
}
}catch(err){
res.send(err)
}
})
解决方案
您的档位查询应如下所示:
var stalls = await stall.find({eventID:req.params.eventID}).populate('exhibitorID')
console.log(stalls)
由于您已经使用条目“exhibitorID”引用了“Exhbibitor”,因此您应该在 .polupate() 函数的论证中使用该字段。
推荐阅读
- godot - 为什么 Godot 对 elif 语句有问题?
- javascript - 如何更新数组的redux状态?
- google-chrome - ASP.Net Core - 调试器启动 Chrome,但不转到应用程序 URL
- python - 为什么 SQLAlchemy 查询返回“NoneType”对象?
- css - 材质 UI 框不会关闭
- batch-file - 用于连续执行多个转换的批处理文件
- windows - CMD START 命令正在打开不同的 .exe
- firebase - Firebase 存储安全规则
- javascript - TensorFlow JS - 将最小/最大值与模型一起保存并在预测数据旁边加载
- javascript - 从反应组件呈现数据时遇到问题 - 建议?