Sequelize.js: Query for not in array ($ne for items in array)

后端 未结 2 2020
悲哀的现实
悲哀的现实 2021-02-08 14:15

I am looking to pull items from a postgres data base with Sequelize, but only return items that have an id that does not equal any items in a given array.

In the Sequeli

相关标签:
2条回答
  • using

    const Op = Sequelize.Op
    where: {
          id: {[Op.notIn]:[1, 2, 3]}
    }
    

    See operators:

    Sequelize exposes symbol operators that can be used for to create more complex comparisons

    0 讨论(0)
  • 2021-02-08 15:12

    There exists $notIn, you must have missed it. Exemplary query with $notIn generates

    SELECT "id", "name"
    FROM "categories" AS "Category"
    WHERE "Category"."id" NOT IN (1, 2);
    

    EDIT

    The documentation you refer to is for 2.0 version of Sequelize, you should update to 3.0.

    0 讨论(0)
提交回复
热议问题