我的api.js中有以下代码:
router.put('/stockAccepted/:id', (req, res, next) =>{
stockSchema.findOneAndUpdate({_id: req.params.id}, {
$set:{
stockAccepted: req.body.stockAccepted
}
},(err, result) => {
if(err) res.json(err);
else res.json(result);
});
});
当我单击接受按钮时,我想增加所有字段。
{"_id":"5ba26ff33318b51e20a80fb3","productExist":true,"productName":"Oppo","supplierId":"5b9f1e2f5929760568283f95","brandId":"5b9d19e8316e8d2660f26394","categoryId":"5b9d20de9c21fd1b78410d52","productPrice":4300,"productQuantity":320,"productMax":10,"productMin":4,"productTimeStamp":"2018-09-19T15:49:07.177Z","__v":0}
我有这个库存方案,上面代码中介绍了所有产品,我如何更新另一个集合中对象数组的所有值?
{"_id":"5bab2f5a0f00b31e98367413","stockAccepted":false,"stockExist":true,"supplierId":"5ba26ed7b6bacb05302f56a8","stockItem":[{"_id":"5bab2f5a0f00b31e98367415","productId":"5ba34f0c133e492a04731c49","productQuantity":1},{"_id":"5bab2f5a0f00b31e98367414","productId":"5ba34f0c133e492a04731c49","productQuantity":2}],"stockTimeStamp":"2018-09-26T07:03:54.932Z","__v":0}