【发布时间】:2017-03-19 09:15:25
【问题描述】:
如何在我的架构中向产品 {type: mongoose.Schema.Types.ObjectId, ref: 'Product'} 发出发布请求,这就是我的架构的样子
const CategorySchema = mongoose.Schema({
name: {
type: String,
required: true
},
img_url:{
type:String,
required: true
},
product: [
{type: mongoose.Schema.Types.ObjectId, ref: 'Product'}
]
})
但我不知道如何发布到产品数组?
router.post('/',(req,res)=>{
const newCategory = newCategory()
category.name = req.body.name;
category.img_url = req.body.img_url;
Category.save(newCategory,(err,category)=>{
if (err) {
console.log(err);
}else {
res.json(status: true)
}
})
})
【问题讨论】:
标签: javascript node.js mongodb mongoose mongoose-schema