Categories
JavaScript Answers

How to query for entries with columns that are not null with JavaScript Sequelize?

Spread the love

To query for entries with columns that are not null with JavaScript Sequelize, we use the Op.ne property.

For instance, we write

Post.update(
  {
    updatedAt: null,
  },
  {
    where: {
      deletedAt: {
        [Op.ne]: null,
      },
    },
  }
);

to select the entries that have the deletedAt field set to a non-null value with Op.ne.

And then we call update with an object to set updatedAt to null for entries that match the condition.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *