#Backend isn't updating front end button pressing

9 messages · Page 1 of 1 (latest)

warped blade
#

what is logged to console?

languid quarry
warped blade
#

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

languid quarry
# warped blade based on that, it appears to be "working". so, your issue would be here: ```js ...

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