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

743
Views
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 answers
Answer question

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 Report

0

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

over 4 years ago · Santiago Trujillo Report

0

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

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