我从angular获取了这些数据
{
"name": "Test name",
"conditions": [
{
"id": "56a53ba04ce46bf01ae2bda7",
"name": "First condition"
},
{
"id": "56a53bae4ce46bf01ae2bda8",
"name": "Second condition"
}
],
"colors": [
{
"id": "56a545694f2e7a20064f228e",
"name": "First color"
},
{
"id": "56a5456f4f2e7a20064f228f",
"name": "Second color"
}
]
}
我想将这个存储在mongoDb的ProductSchema中,但我不知道如何为此创建模式。
var ProductSchema = new Schema({
name: String,
conditions: [Array],
colors: [Array]
});
如何将其保存到服务器控制器中的模型
var product = new Products({
name: req.body.name,
conditions: req.body.conditions,
colors: req.body.colors
});
当我使用这个Schema和这个controller时,除了名字和ObjectId之外,在集合中得到的记录为空。如何创建正确的Schema和controller?