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

744
Vistas
err TypeError: values.map is not a function

I'm trying to find post by id and add comment to it .

I'm using postgreSQL.

Here is my model

   const Sequelize = require('sequelize')
const db = require('../../config/database')

const Posts =db.define("Topics",{
    id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    title : {
        type : Sequelize.STRING,
    },
    description : {
        type: Sequelize.STRING
    },
    username : {
        type: Sequelize.STRING
    },
    comment : {
        type:Sequelize.ARRAY(Sequelize.STRING),
        defaultValue : [],
        allowNull: false
    }

})
module.exports = Posts;

Here is my nodeJS Request.

    app.put('/addComment/:id', (req, res) => {
    Posts.update({
            comment: req.body.comment
        },
        {
            where: {
                id: req.params.id
            }
        }).then((post) => {
        res.send(post)
    }).catch((err) => {
        console.log("err", err);
    });
})

I'm testing my server using postman but whenever i try to send updated data to the databse I'm always getting this error err TypeError: values.map is not a function.

Any suggestions on how to fix this please? Also in my DB datatype for comment array is text[] I also tried to change update to create but with no results

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

you have defined comment in the model of type Array of strings but while update you are directly passing the single string please pass in the array format

Posts.update({
        comment: [req.body.comment]   // note the square brackets for array
    },
    {
        where: {
            id: req.params.id
        }
    }).then((post) => {
    res.send(post)
}).catch((err) => {
    console.log("err", err);
});
over 4 years ago · Santiago Trujillo Denunciar

0

I fixed the issue by changing req.body.comment to the [req.body.comment].

over 4 years ago · Santiago Trujillo Denunciar

0

check your req.body.comment and sent it as array

req.body.comment = ['test']
over 4 years ago · Santiago Trujillo Denunciar
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