Update Controller
exports.UpdatePanelMembers = (req, res) => {
const { panelId } = req.params;
if (panelId) {
Panel.findOneAndUpdate(
{ _id: panelId },
{
panelMembers: {
member1: {
memberId: req.body.panelMembers.member1.memberId,
fullName: req.body.panelMembers.member1.fullName,
username: req.body.panelMembers.member1.username,
},
member2: {
memberId: req.body.panelMembers.member2.memberId,
fullName: req.body.panelMembers.member2.fullName,
username: req.body.panelMembers.member2.username,
},
member3: {
memberId: req.body.panelMembers.member3.memberId,
fullName: req.body.panelMembers.member3.fullName,
username: req.body.panelMembers.member3.username,
},
},
}
).exec((error, result) => {
if (error) return res.status(400).json({ error });
if (result) {
res.status(202).json({ result });
}
});
}
};
In this code, if I update member1 details only, other data will be erased. So I want to update only relevant data like this postman JSON.
Postmen JSON Code
{
"panelMembers": {
"member1": {
"username":"john.j",
"fullName":"John Jade",
"memberId":"member123"
}
}
}