U kunt de waarde dynamisch instellen en doorgeven in de query
function update_total_credit(total_amount, topup_value) {
//The flag value means your breakpoint where you decide which value should go in query, you can change on your requirement basis
var flag = 1; // increment by 1 every time
if (!flag)
flag = -1; // decrement by 1 every time
User.findOneAndUpdate({
email: user_email
}, {
$inc: {
credit: flag
}
},
function(err, response) {
if (err) {
res.json(0);
} else {
res.json(response.credit);
}
});
}
Zie hier de referentie voor $inc