#Backend isn't updating front end button pressing
9 messages · Page 1 of 1 (latest)
Will copy and past. GOing to find it
also FYI, both of the following are identical:
{ key: key, value: value }
{ key, value }
based on that, it appears to be "working". so, your issue would be here:
const roomToUpdate = await ChatRoom.findByIdAndUpdate(
roomId,
{ $set: { [keyProp]: req.body.value } },
{ new: true }
);
doesn't really make sense that you're making keyProp an array, then trying to use that as the property name to update
Ah so it seems from how I'm constructing key prop. Using an array as a property name in the update query might not align with MongoDB's expectation then?
Should I instead create a string path so something like the below instead or is it something to only update in that variable roomToUpdate?
if (optionalEvent !== null && optionalEvent !== undefined) {
keyProp += `.${optionalEvent}`;
if (optionalInterval !== null && optionalInterval !== undefined) {
keyProp += `.intervals.${optionalInterval}.${req.body.key}`;
} else {
keyProp += `.${req.body.key}`;
}
}```
And that worked..
only for one button..pressing the other buttosn doesnt even work