假设我的模型如下所示:
const PostSchema = new mongoose.Schema({
award: [
one: {
type: Number,
default: 0
},
two: {
type: Number,
default: 0
},
three: {
type: Number,
default: 0
},
four: {
type: Number,
default: 0
}
]
)}
我是一个控制器,当由职位ID调用该控制器时,它将增加出现在主体中的奖励数量(例如“两个”)。
exports.awardPost = asyncHandler(async (req, res, next) => {
const post= await Post.findById({id: req.params.cardid},
if(!post){
res.status(400).json({
success: false,
message: 'Card not found'
})
}
post.update("Increment by one req.body.awardname"); <- What is the best way to do that here ?
res.status(200).json({
success: true,
card
})
});
我已经为此苦苦挣扎了一段时间,在这种情况下正确的方法是什么?