【发布时间】:2020-07-26 19:06:10
【问题描述】:
我在文档(产品)中有对象数组(批次)。
将新对象推送到该数组后,我只想在 axios 发布响应中返回新添加的对象的自动生成 ID。请问怎么做?
batchRoutes.route('/add/:id').post(function(req,res){
Product.findOneAndUpdate(
{"_id":req.params.id},
{$push:{"batches":req.body}},
function(err,batch){
if(err){
return res.json({'status':false});
}
else{
return res.json({'status':true});
}
});
});
架构
let Product= new Schema({
productName:{
type:String
},
batches:[{
batchNo:{
type:String
},
expDate:{
type:Date
},
}]
},
【问题讨论】:
标签: javascript node.js reactjs mongoose