I'm a C++ dev who inherited a node.js project which has annoying bug which is really difficult to fix with my limited mongoose expertise.
The function below get's data from a form. It should save the data from the form and change one extra field. The code below is probably over complicated for that goal. But when I test this on my local machine it saves the question and changes the status perfectly but on the final server it only works 33% of the time.
Anyone can point me in the right direction here?
// publish
router.put('/questions/publish/:id', passport.authenticate('jwt',
{session: false}),
async function(req, res) {
var id = req.params.id
var question = await Questions.findOneAndUpdate({
_id: req.params.id
}, req.body);
question = await Questions.findById(id);
question.status = "Done"
question.save(function() {
res.send(question);
})
});