Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

745
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

0

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

over 4 years ago · Santiago Trujillo Relatório

0

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

req.body.comment = ['test']
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda