Sequelize select * where attribute is NOT x

37,234

Solution 1

Try this

model.findAll({where: {attribute: { $not: 'x'}}})

Sequelize actually provides many operators for you to get your filter data.

You can refer to the link here

Solution 2

Updated method, for modern Sequelize:

model.findAll({
  where: {
    someAttribute: {
      [sequelize.Op.not]: 'some value'
    }
  }
});
Share:
37,234
joemillervi
Author by

joemillervi

Fullstack Dev

Updated on May 21, 2020

Comments

  • joemillervi
    joemillervi almost 4 years

    looking at the docs you can use model.findAll({where: {attribute: x}}). However, I want to select all attributes that are simply NOT x. I was looking into a regular expression here but that seemed like not an optimal solution.

    What is the best way to do this?