【发布时间】:2019-11-14 04:35:10
【问题描述】:
我正在尝试使用 Postman 将对象数组发送到 mongodb,但子类别数组始终为空。
{
"name": "Category 1",
"subcategory": [
{
"name": "value 1, value2"
}
]
}
我的猫鼬模式:
const categorySchema = new mongoose.Schema({
name: {
type: String,
required: true,
minlength: 5,
maxlength: 255
},
subcategory: [
{
name: {
type: String
}
}
]
});
我的邮递员设置是“原始”,JSON(application/json)
【问题讨论】:
-
我在架构中看到您在传递字符串数组时拥有
name: { type: String }? -
你能说明你是如何将它保存在你的数据库中的吗?我们已经看到了架构和请求正文,请显示将请求正文保存到数据库集合的代码
-
@RaviShankarBharti,是的。这就是问题所在。只是不知道如何修复它,现在我看着它。
let category = new Category({ name: req.body.name });