Saturday, 18 March 2017

How to make post request to child attribute

How do i make a post request to the product {type: mongoose.Schema.Types.ObjectId, ref: 'Product'} in my schema this is what my schema looks like

const CategorySchema = mongoose.Schema({
name: {
 type: String,
 required: true
},
img_url:{
 type:String,
 required: true
},
product: [
 {type: mongoose.Schema.Types.ObjectId, ref: 'Product'}
 ]
})

but i don't know how i can post to the product 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)
    }
  })
 })



via Paul dolo

No comments:

Post a Comment