0
const KeyContactsPersonsSchema = new Schema({
name: {
required: true,
type: String
},
contactNumber: {
required: true,
type: String
},
email: {
required: true,
type: String
}
});
上述定義的模式已被列入以下模式keyContactsPersons屬性貓鼬陣列沒有父文檔中保存
const CompanySchema = new Schema({
name: {
type: String,
required: true,
unique: true,
trim: true
},
address: {
type: String,
required: true,
trim: true
},
contactNumber: {
type: String,
required: true,
trim: true
},
logo: {
type: String,
required: true,
trim: true
},
keyContactsPersons: [KeyContactsPersonsSchema],
billingDetails: {
type: String,
required: true,
trim: true
},
assignedEmployee: {
type: Schema.Types.ObjectId,
required: true,
trim: true
},
status: {
type: Boolean,
default: false,
required: true,
trim: true
}
}, {
timestamps: true
});
最後保存傳遞給CompanyModel模型 JSON目的是like.while我試着去挽救這一點,讓我像
keyContactsPersons.0.email一個錯誤:路徑
contactNumber
是必需的。, keyContactsPersons.0.name:路徑name
是必需的。
"company":{
"name":"Leafy Code",
"address":"Hokandara",
"contactNumber":"075227785",
"logo":"/logo",
"billingDetails":"billingDetails",
"assignedEmployee":"5997e71ab6a13500018106b9",
"status": true,
"keyContactsPersons": [
{
"name":"demo person",
"contactNumber":"0771568952",
"email":"[email protected]"
}
]
}
const newCompany = new CompanyModel(company);
newCompany.save();
是'你給company'變量'CompanyModel'等於'「公司」:... 'like:'company = {「company」:...}'? –