mongoose $inc findByIdAndUpdate failed mongoose $inc findByIdAndUpdate failed mongoose mongoose

mongoose $inc findByIdAndUpdate failed


In your app's heroku logs , this line
Error: Can't set headers after they are sent.

you are sending response but without return statement.so if error occurs for some reason, it falls in the if check (your code):

if(err) res.json({error: err});

but it will not exit the process and next part also executes where you are also returning the response.

res.json(c).send({modif: c.modif});

so the right way to send response is

router.put('/:id', function(req, res, next) {        models.rappel.findByIdAndUpdate(req.params.id,       {$inc: { modif: 1}},  {new: true}, function(err, c){        if(err) return res.json({error: err});        return res.json(c).send({modif: c.modif});       });      });