gpt4 book ai didi

node.js - 发送 postman 数组中的对象数组始终为空

转载 作者:太空宇宙 更新时间:2023-11-03 23:56:31 24 4
gpt4 key购买 nike

我正在尝试使用 Postman 将对象数组发送到 mongodb,但子类别数组始终为空。

{
"name": "Category 1",
"subcategory": [
{
"name": "value 1, value2"
}
]
}

我的 Mongoose 架构:

const categorySchema = new mongoose.Schema({
name: {
type: String,
required: true,
minlength: 5,
maxlength: 255
},
subcategory: [
{
name: {
type: String
}
}
]
});

我的 postman 设置是“原始”,JSON(application/json)

enter image description here

最佳答案

问题是您没有在集合中保存子类别

你可以尝试:

let category = new Category({ 
name: req.body.name,
subcategory : req.body. subcategory
});

关于node.js - 发送 postman 数组中的对象数组始终为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56870922/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com