我想从 tvshow 模式填充 myshow 模式中的 show_detail ? 我不知道如何填充对象数组,特别是对象中的元素
const mongoose = require('mongoose');
const Tvshow = require('./tvshows');
const Schema = mongoose.Schema;
const MyshowScheme = new Schema({
username : {
type : String
},
shows : [
{
show_detail : {
type : Schema.Types.ObjectId,
ref : 'Tvshow'
},
showid : {
type : Number,
},
info : {
season : {
type : Number,
},
episode : {
type : Number,
}
}
}
]
})
module.exports = mongoose.model('Myshow',MyshowScheme);
答案 0 :(得分:0)
很简单:
Myshow.find({}).populate('shows.show_detail')