const mongoose=require('mongoose');
let contentSchema=mongoose.Schema;
module.exports=new contentSchema({
category:{
type:mongoose.Schema.Types.ObjectId,
ref:'categories'
},
title:String,
desc:String,
content:String
});
ref
的值是categories的模板
router.get('/content',function(req,res){
Contents.find().populate('category').then(function(contents){
console.log('~~~~~~~~~~~~~~~~~~contents');
console.log(contents);
res.render('admin/content_index',{
userInfo:req.userInfo,
contents:contents
});
})
})
調用聯合查詢需要使用
populate
方法。。。。。