是否可以在mongoose中引用子文档架构?

时间:2015-01-16 06:23:04

标签: node.js mongodb mongoose database

是否可以在mongoose中引用子文档架构?

就像下面的

var sectionSchema = mongoose.Schema(
{
    id:{type:String,required:true},
    name:{type:String,required:true}
});
var courseSchema = mongoose.Schema(
{
    id:{type:String,required:true},
    name:{type:String,required:true},
    sections:[sectionSchema]
});
var studentSchema = mongoose.Schema(
{
    id:{type:String,required:true},
    name:{type:String,required:true},
    course:{type:mongoose.Schema.Types.ObjectId,ref: 'courseSchema'},
    section:{type:mongoose.Schema.Types.ObjectId,ref: 'sectionSchema'},
    contactnumber:{type:String,required:true},
    parentname:{type:String,required:true}
});
var schoolSchema = mongoose.Schema(
{
    id:{type:String,required:true},
    name:{type:String,required:true,unique:true},
    address:{type:String,required:true},
    year:{type:String,required:true},
    contactnumber:{type:String,required:true},
    courses:[courseSchema],
    students:[studentSchema]
});

var School = mongoose.model('School',schoolSchema);

在上面的模型中我有课程里面的部分是学校文件。 我有学生模式,在学校文档中我想要课程模式和部分指向部分模式。所以可以在mongoose中引用子文档模式。

0 个答案:

没有答案