I have a programming challenge where I need to increment one value if condition x is true, and another value if condition y is true. The issue I'm facing is that my current system also resets the value that is not being updated back to 0, which is not desired. I am looking for a solution to prevent this from happening and keep the other value unchanged.
Below is the snippet of code I am working with:
leaderboard.findOneAndUpdate(
{
userID: interaction.user.id
},
{
userID: interaction.user.id,
$inc: { accepts: 1 },
denies: 0
},
{
upsert: true, new: true
}, (err: any, doc: any) => {
if (err) console.log(err)
console.log(`Updated ${interaction.user.username}'s accepts to ${doc.accepts} `)
})
In this scenario, I want the 'accepts' value to be incremented by 1, while keeping the 'denies' value the same as it is already stored in MongoDB.