How can I get a column based on id using sequelize query

My sequelize.js query is not giving me correct result, I am trying to create a query based on the below sql query:

select views from userblogs where id=4;

current sequelize.js one- this is not working . Could someone please advise what correction need to do

    const usersBlogSchema = require('./modals/userblogs');
    const BlogModel = usersBlogSchema(sequelize, DataTypes);
    const blogId =  req.query.id;
    const dataCount = await BlogModel.findOne({ attributes: ['views'] }, {where: { id: blogId } });

>Solution :

I think it’s just one argument to the findOne function:

const dataCount = await BlogModel.findOne({ attributes: ['views'], where: { id: blogId } });

Leave a Reply