I need to update array field in subdocument and that works
User.findOne({ _id: id }, (err, user) => {
if (!user) res.json({ error: "Email has not be found" });
user.set({ "files.0.approved": isApproved });
user.save((err, updatedUser) => {
return res.send(updatedUser);
});
});
Nevertheless, I wonder how can I make it dynamic ? Since here I'm passing index manually - files.0.approved.
I tried using template strings, but it complains.
I also tried referring here, but could not figure it out.
If we assume that I can get index of array with req.body.index, how to prevent it from being hard-coded ?