【发布时间】:2019-01-31 00:08:55
【问题描述】:
我在猫鼬中创建了两个集合,如下所示 1.类别架构 const categorySchema = new Schema({
name:{
type:String,
required:true
},
cat_type:{
type:String,
enum:['images','quotes','videos']
},
image:{
type:String
},
videoId:{
type:Number
}
})
const Category = mongoose.model('categories',categorySchema);
module.exports = Category;
2.视频架构
const videoSchema = new Schema({
videoId:{
type:String
},
title:{
type:String,
required:true
},
cat_id:{
type:Schema.Types.ObjectId,
ref:'categories'
},
description:{
type:String
},
url:{
type:String
},
publishedAt:{
type:String
}
})
const Video = mongoose.model('videos',videoSchema);
module.exports = Video
我正在使用以下查询来获取视频和视频的类别详细信息
Video.find({}).
populate('categories')
.exec(function(err, data){
console.log(data);
})
但我只是得到视频表的结果,而不是类别表,我在这做错了什么?
【问题讨论】: