Filtering Records From Tables in Sequelize
Sequelize·3 min read·Jan 1, 2025
In Sequelize, the Op object provides a list of built-in operators, such as Op.eq for =, Op.and for AND, Op.between for BETWEEN ... AND ..., etc:
const { Op } = require('sequelize');To filter records based on conditions, you can use the where property combined with a built-in operator of the Op object:
{ where: { <attribute>: { [Op.<operator>]: <value> } }}Where:
-
attributeis the name of the column you want to perform a comparison of (e.g.,first_name). -
operatoris a built-in operator (e.g.,eq).
Unlock the Build RESTful APIs in Node.js module
Learn how to build real database-backed and framework-powered RESTful APIs with MySQL, Sequelize, and Express.
You get immediate access to:
- 37 focused lessons across MySQL, Sequelize, backend, and Express
- 4 real-world projects with commented solutions
- Ongoing updates to this bundle
- Lifetime access to this bundle