I'm new to mongodb. I'm doing this student project which is a web app that generates multiple choices. After user submits answer, app checks user's answers against the correct ones to provide feed back.
I have the question bank with correct answer stored in one collection. After a user submits his answer, an array contains _id with user's choice gets sent to the nodejs backend.
To check user's answers, my approach now would be something like:
app.post('/submitquiz', function (req, res) {
var arr = [], answer;
for (answer in req.body){
var correctChoice = questionModel.find({_id:answer._id}).correctChoice;
if (correctChoice != answer.choice){
arr.push({
'_id':answer._id,
'correctChoice': correctChoice
})
}
}
res.send(arr);
});
Wanna know if there's an elegant way to do this in mongodb, is there anything built in I can utilize to achieve this?
Thanks!