例如,这是一个MongoDB模式:
const humanBodySchema = new Schema({
Head:{
eyeColor: String,
noseShape: String,
lipShape: String,
hair: Boolean,
}
},{
timestamps:true,
})
当我发送帖子或发出请求时,我将需要填写所有字段,如下所示:
{
"Head":
{
"eyeColor": "Brown",
"noseShape": "Pointy",
"lipShape": "Puckered",
"hair": "0"
}
}
例如,如果我只想发送头发字段,该怎么办?
答案 0 :(得分:0)
我知道了。我必须在字段上将type属性设置为“ Schema.Types.Mixed”。因此,humanBodySchema必须是这样的:
const humanBodySchema = new Schema({
Head:{
eyeColor: String,
noseShape: String,
lipShape: String,
hair:{Schema.Types.Mixed},
}
},{
timestamps:true,
})