node.js - mongoose update a value in a document using model.update -
What am I doing wrong here, do I want to update the score?
The problem is executed without the code of errors, but does not update the score. Team.findOne ({name: req.body.team}, function (fault, team data) {if (teamData) {var a = TeamData.score + 1; Team.update ({ Name: req.body.team}, {$ set: {Score: a}});} else {console.log ()}}}); As Muhammad Ali said, a callback function is required for the update, which is probably your problem. But there is an easy way to do this:
Team.findOne ({name: req.body.team}, function (mistake, teamadata) {if (teamData) {teamData.score + = 1 teamData.save (function (mistake) {if (err) // something to do});} else {console.log (err);}});
Comments
Post a Comment