I want to implement an award system and I'm exploring the most efficient approach to achieve this. Each time a specific award is earned, I need to increase its corresponding value by one. Here is what my model structure looks like:
const CardSchema = new mongoose.Schema({
awards: {
"awardOne": 0,
"awardTwo": 0,
"awardThree": 0,
"awardFour": 0
},
userId: {
type: mongoose.Schema.ObjectId,
ref: 'User',
required: true
},
})
What would be the optimal method for incrementing, let's say, awardOne by one?
exports.awardCard = asyncHandler(async (req, res, next) => {
const id = req.params.id;
const awardOption = req.body.award; //Name of the award
const card = Card.findById(id)
if(!card){
res.status(200).json({
success: false,
message: "Card not found"
}
card.update ... //Uncertain about how to handle the update here
card.save()
res.status(200).json({
success: true,
card
})
});