const onboarderSchema = new Schema({
name: {
type: String,
required: [true, "name field is required"]
},
email: {
type: String
},
project: {
type: Object,
projectName: {
type: String,
required: [true]
},
projectDescription: {
type: String
},
manager: {
type: String,
required: [true]
},
mentor: {
type: String,
required: [true]
},
technologies: {
type: [Number],
required: [true]
}
}
});
这是我正在研究的项目架构。作为对象的项目将动态添加不同的项目。那么我应该将项目类型更改为数组还是其他什么?无法弄清楚该怎么做。请建议。
使它成阵。记住对象是针对具有固定字段和值的单个信息。另一方面,数组是保存许多信息,您可以根据需要动态放置对象。然后它将被称为对象数组。保持数组中的对象字段相同,以保持一致性和灵活的查询操作。
如果你想在你的数据库中有多个项目,项目字段应该是一个数组
project:[{projectName:"p1"},
{projectName:"p2"},
{projectName:"p3"}]
或者像这样
project:["p1","p2","p3"]