简体   繁体   中英

How to make Sequelize $between query?

I use node.js and Sequelize ORM for my project. I'm trying to get all rows where stage is "pending" AND date between 2 and 10 (fake dates). This is my query:

const stain = await Gyn.findAll({
        where: {
            stage: `pending`,
            lastUpdate: {
                [Op.$between]: [startDate, endDate]
            }
        }
    });
console.log(stainQc)

I have only 2 rows in table. I see that one is matching my query, but console.log(stain) in my code shows that there is empty array. But it has to be one item. What I'm doing wrong?

UPDATE: When I remove

lastUpdate: {
         [Op.$between]: [startDate, endDate]
}

it finds my row as it should by "pending".

As mentioned in comments, this is just a typo. Remove $ before operator:

lastUpdate: {
    [Op.between]: [startDate, endDate]
}

Sequelize official docs reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM