猫鼬模式
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const ResponseSchema = new Schema({
title: {
type: String,
required: true
},
status: {
type: String,
required: true
}
});
const QuestionSchema = new Schema({
quiz: {
type: Schema.Types.ObjectId,
ref: "quizzes"
},
title: {
type: String,
required: true
},
response: [ResponseSchema],
score: {
type: String,
required: true
}
});
module.exports = Question = mongoose.model("questions", QuestionSchema);
我想删除问题文档内响应数组中的元素,然后使用Promises返回新问题,请提供任何帮助!
router.delete(
"/:idQ/response/:idRes",
// passport.authenticate("jwt", { session: false }),
(req, res) => {
Question.findOne,(
{ _id: req.params.idQ },
{ $pull: { "questions.response": { _id: req.params.idRes } } }
)
.then(() => {
Question.find().then(question => {
res.json(question);
});
})
.catch(err => res.status(404).json(err));
}
);
我试过了,但是没有更新