How do I query for two columns to be equal using Sequelize?

Update: Another way of writing code by using Operators(Op) from sequelize.

const { Op } = require('sequelize');

db.WorkbookQuestion.count({
  where: {
    QuestionId: dbQuestion.id,
    CorrectAnswerId: {
        [Op.eq]: sequelize.col('AnswerSelectedId')
    }
  }
});

I was stuck on this for a while today until I found this answer. I also found another way of doing the same query so will leave another answer here.

db.WorkbookQuestion.count({
  where: {
    CorrectAnswerId: {
        $col: 'AnswerSelectedId'
    }
  }
});

You can do it via sequelize.where():

db.WorkbookQuestion.count({
  where: sequelize.where(
    db.sequelize.col('CorrectAnswerId'),
    db.sequelize.col('AnswerSelectedId')
  )
});