I am trying to push an element to an array in mongoose. I am doing it with update and $push. But it is not updating it in the database. This is my code. routes.js:
This is how you can update a model in mongoose (using async await) :
let updatedModel = await Model.findByIdAndUpdate(req.params.id,
{ $push: { accounts:{"name": "foo", "idAccount": 123456} } },
{ 'upsert': true });
or in your code
Maybe you have missed the {new: true, upsert: true } if you want the updated document to be returned to you.
Chooser.update({_id: req.params.id}, {$push: {accounts: {"name": "foo", "idAccount": 123456}}},{new: true, upsert: true });