2017-06-28 20 views
0

如何设置类型的默认图像:'缩略图'和URL:'https://blalblabla'? 我可以用猫鼬做计划吗?更多细节?如何设置类型的默认图像:'缩略图'和URL:'https:// blalblabla'?

const Images = new Schema({ 
kind: { 
     type: String, 
     enum: ['thumbnail', 'detail'], 
     required: false 
    }, 
    url: { 
     type: String 
    }, 
}); 

const Tags = new Schema({ 
    label: { 
     type: String 
    }, 
}); 

const ArticleScheme = new Schema({ 
    images: [Images], 
    title: {type: String, required: true}, 
    author: {type: String, required: true}, 
    text: {type: String, required: true}, 
    views: { 
     type: Number, 
     default: 123 
    }, 
    tags: [Tags], 
    createdAt: { 
     type: Date 
    } 
}); 
+0

嗨,欢迎来到Stack Overflow,请花点时间浏览[欢迎导览](https://stackoverflow.com/tour),在此处了解您的方式(并获取您的第一个徽章),阅读如何创建[Minimal,Complete和Verifiable示例](https://stackoverflow.com/help/mcve)并检查[如何提出好问题](https://stackoverflow.com/help/how-to - 问),所以你增加了获得反馈和有用答案的机会。 – DarkCygnus

回答

0

你只需要添加属性默认

kind: { 
    type: String, 
    enum: ['thumbnail', 'detail'], 
    default: 'thumbnail' 
} 

你不会在这种情况下,需要required: false