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

143
Views
Update nested JSONB in postgresql using sequelize

I am using NodeJS to update a nested info in the database but I can't seem to figure this out.

Data in database

 {
            "id": 1,
            "data": {
                "__v": 0,
                "_id": "5887e1d85c873e0011036889",
                "text": "you have to change this text",
                "type": "cat",
                "used": true,
                "user": "5a9ac18c7478810ea6c06381",
                "source": "user",
                "status": {
                    "feedback": "",
                    "verified": true,
                    "sentCount": 1
                },

My code to update:

UpdateFacts: async function (req, res, next) {
    const {text} = req.body
    const {id} = req.params

    if(!id){
      return res.status(400).send({message:'please provide id'})
    }

    if(!Object.keys(req.body).length){
      return res.status(400).send({message:'please provide text'})
    }

    const checkIfFactExist = await Facts.findOne({
      where: {
        id
      }
    })

    if(!checkIfFactExist){
      return res.status(404).send({message:'this id does not exist'})
    }

    try {
      if(text){
        checkIfFactExist.data.text = text
      }

      checkIfFactExist.save()
      return res.status(200).send({message:'updated'})
    } catch (error) {
      return res.status(500).send(error.message)
    }

Data is the column and text is the field am trying to change but it's not working.

about 4 years ago · Juan Pablo Isaza
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!