Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    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 } });
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading