I have a mongo db where I have create a record that has an object within an array (e.g. employees: [{name:Bob, Age: 30}]. I now want to update the object within the array so it looks like [{name:Bob, age: 30, pay:400}]. How do I do this within a node/express route? If I use something like:
router.put("/addPay/:id",function(req,res){
Team.findByIdAndUpdate(req.params.id,{$push:{employee: {$each:
[{pay:req.body.pay}]}}},........
this just pushes {pay: XXX} as a separate object into the array [{name:Bob, age: 30, pay:400}, {pay: XXX}] rather than inserting it into the object already there. I know there are plenty of questions about pushing into objects and arrays etc on SO but I couldn't find a similar example to this situation. Thanks!
req.bodycontain employee's name ?employee.0.pay