Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

145
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda