Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

61
Views
How can I update just one atribute in my MySQL database using js?

I have a little question about updating just one attribute and not all like in this code.

router.put("/update/:id", (req, res) => {
    const id = req.params.id;
    Account.update(req.body, {
            where: { id: id },
        })
        .then((num) => {
            if (num == 1) {
                res.send({
                    message: "Informatiile au fost actualizate cu succes.",
                });
            } else {
                res.send({
                    message: `Nu pot actualiza informatiile pentru contul cu id=${id}.`,
                });
            }
        })
        .catch((err) => {
            res.status(500).send({
                message: "Eroare actualizare date pentru id=" + id,
            });
        });
});

One register from my database looks like this:

{
  name: 'x',
  password: 'x',
  activated: 0
}

All I want to do is to make that 0 in 1 and I don't know what I have to change in my code because if I use this code, I will update all parameters (name, password, activated) and I want to update just one.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It looks like you are using sequelize. In sequelize to update only one field you would pass an object with only one field into the .update method as it can be seen in the following snippet.

router.put("/update/:id", (req, res) => {
    const id = req.params.id;
    Account.update(
        {
          activated: req.body.activated
        }, {
            where: { id: id },
        })
        .then((num) => {
            if (num == 1) {
                res.send({
                    message: "Informatiile au fost actualizate cu succes.",
                });
            } else {
                res.send({
                    message: `Nu pot actualiza informatiile pentru contul cu id=${id}.`,
                });
            }
        })
        .catch((err) => {
            res.status(500).send({
                message: "Eroare actualizare date pentru id=" + id,
            });
        });
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!