Hi everyone,
I'm trying to update a document in my mongodb. I try this by the code down below. With the code I am everytime updating the first data in the array called 'Kassen'. My goal in this question is to know how I can define that I want to update for example the second or third dataset of the 'Kassen' array. I want to use the variable called 'kasnumber' to define which dataset I want from the array. What you can see in the image I've got the same problem with the array called 'afdelingen' but I think it will work the same way.
router.patch('/:postId',async (req, res) => {
try{
let kasnumber = parseInt(req.body.user.kasnumber);
const updatedPost = await Post.updateOne(
{Gebruikersnaam: req.params.postId},
{$set: {
FirstName: req.body.user.FirstName,
bedrijf:{
Kassen: [{
KasId: req.body.user.KasId,
Name: req.body.user.KasName,
},
PassWord: req.body.user.PassWord
}
}
);
console.log(updatedPost);
res.json(updatedPost);
}
catch(err) {
res.json({message: err})
}
});