0
Wie ich eine Post-Anforderung an das Produkt {type: mongoose.Schema.Types.ObjectId, ref: 'Product'}
in meinem Schema machen tue, ist das, was mein Schema wieWie Post-Anforderung zu Kind Attribut machen
const CategorySchema = mongoose.Schema({
name: {
type: String,
required: true
},
img_url:{
type:String,
required: true
},
product: [
{type: mongoose.Schema.Types.ObjectId, ref: 'Product'}
]
})
aber ich, wie ich schreiben kann nicht wissen, schaut zu das Produkt-Array?
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)
}
})
})