如何设置类型的默认图片:'thumbnail'和网址:'https://blalblabla'? 我能用mongoose计划吗?更多细节?
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 :(得分:0)
您只需添加属性默认值
kind: {
type: String,
enum: ['thumbnail', 'detail'],
default: 'thumbnail'
}
在这种情况下,您不需要required: false
。