我曾尝试在我的盘问模型中添加喜欢/不喜欢/满意的变量,但是当我查看数据库(Atlas MongoDB)时,只能看到最初存在的变量(标题,说明)。
我的数据库有一个“挑战”集合,具有以下结构的4个挑战(不喜欢/不喜欢/满意)。如何在此处将“喜欢/不喜欢/满意”及其默认值0包括在内?
QUERY RESULTS 1-4 OF 4
_id:5eb98c06a1f08159842b430d
title:"aaaaaaa"
description:"aaaaaaaaa"
__v:0
const challengeSchema = new Schema({
title: String,
description: String,
initiator: {type: Schema.Types.ObjectId, ref:"User"},
likes: { type: Number, default: 0 },
dislikes: { type: Number, default: 0 },
satisfaction: { type: Number, default: 0 }
})
//add challenge
router.post("/startchallenge", (req,res) => {
Challenge
.create({
title: req.body.title,
description: req.body.description,
likes: req.body.likes,
dislikes: req.body.dislikes,
satisfaction: req.body.satisfaction
})
.then((response) => {
res.json(response)
})
.catch(error => {
res.json(error)
})
})