Home > other >  How to make Sequelize search by several fields?
How to make Sequelize search by several fields?

Time:01-26

I spent a lot of time to find an answer, but did not find it

So, my problem is - I am trying to make where condition like this:

where: {
        [Op.and]:
          [
            { skill: 'IDE', months: { [Op.gte]: 28 } },
            { skill: 'REST', months: { [Op.gte]: 20 } },
          ]
      }

But it just does not work May be it is not right way to do what i need?

CodePudding user response:

probably you want an or like that.

const { Op } = require("sequelize");
Post.findAll({
  where: {
    [Op.or]: [
      { authorId: 12 },
      { authorId: 13 }
    ]
  }
});

CodePudding user response:

I think you can not use it that. You can try below codes.

where: {
        [Op.and]:
          [
            { [Op.and]:[{skill:'IDE'},{months:{[Op.gte]:28}] },
            { [Op.and]:[{skill:'REST'},{months:{[Op.gte]:20}] },
          ]
      }

  • Related