I tried to make async and await function in mongoose. but in one case it simply didn't work while in another case it shows syntax error.
here is my code
exports.updateDiscount= async (_id,discount) =>
{
try
{
console.log(_id,discount);
Discount.findOne({_id},(err,user) =>
{
if(user)
{
user.discountRate=parseFloat(discount);
let saveUser= await user.save();
if(saveUser)
{
console.log("Discount saved");
return true
}
}
})
} catch(err)
{
console.log(err);
}
}
I am using the thing function in another module
if( updateDiscount(item.userid,discount) === true)
{
}
const user = await Discount.findOne({_id})?