Olga K Olga K - 5 months ago 7
Node.js Question

mongoose doesn't update model by ID

apiRoutes.put('/intake/:id', function(req, res) {
var id = req.params.id;
Intake.findById({id, function(err, intake) {
if (err)res.send(err);

intake.check = true;
intake.save(function(err) {
if (err) {return res.json({success: false, msg: 'Error'});}
res.json({success: true, msg: 'Successful update check state.'});
});
}})
});


What's problem? In console i see ID, it's ok, but database have no change

Answer
Intake.findById(/*remove { here*/id, function(err, intake) {
      if (err)res.send(err);

        intake.check = true;
        intake.save(function(err) {
        if (err) {return res.json({success: false, msg: 'Error'});}
      res.json({success: true, msg: 'Successful update check state.'});
    });
  })