Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在mongoose模式中创建一个子模式';它不是数组_Mongoose - Fatal编程技术网

如何在mongoose模式中创建一个子模式';它不是数组

如何在mongoose模式中创建一个子模式';它不是数组,mongoose,Mongoose,我有一个猫鼬模式,其中有4个子模式。我一直在关注嵌入文档的文档 var scenarios = new Schema({ title: 'String', type: 'String', description: 'String', authorId: 'String', categories: [categoriesSchema], subcategories: [subcategories_schema], presentatio

我有一个猫鼬模式,其中有4个子模式。我一直在关注嵌入文档的文档

var scenarios = new Schema({
    title: 'String',
    type: 'String',
    description:  'String',
    authorId:  'String',
    categories:  [categoriesSchema],
    subcategories: [subcategories_schema],
    presentation: [presentations_schema],
    scripts: [scripts_schema],
    revision: 'String',
    createDate: 'String',
    updateDate: 'Date',
    active: 'Boolean',
    display:  'Boolean',
    status: [statusSchema],
    video: [video_schema],
    bundleId: [bundleSchema],
    sortOrder: 'Number'
});

例如,我的问题是,如果我不希望演示文稿是一个数组,并且只希望每个场景允许一个演示文稿,那么在模式定义中是否有处理该问题的方法?

如果不声明数组,就不能嵌入模式对象,但是可以将演示文稿模式定义为普通javascript对象(不是架构实例):

然后你可以做:

presentation: presentations_schema

在中,请参见第一个示例中的元字段。

如果“presentation”是一个子模式,请假设如下:

var presentation_schema = new Schema ({
name:{
     type: String,
     }
});
您希望它只在主模式中出现一次,而不是将它嵌入这些方括号[]中,方括号[]表示数组或列表,您可以这样表示它

演示:演示模式

var presentation_schema = new Schema ({
name:{
     type: String,
     }
});