简体   繁体   English

如何使Sequelize $ between查询?

[英]How to make Sequelize $between query?

I use node.js and Sequelize ORM for my project. 我为我的项目使用node.js和Sequelize ORM。 I'm trying to get all rows where stage is "pending" AND date between 2 and 10 (fake dates). 我正在尝试获取阶段“待定”且日期介于2到10(假日期)之间的所有行。 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. 我表中只有2行。 I see that one is matching my query, but console.log(stain) in my code shows that there is empty array. 我看到一个查询与我的查询匹配,但是我的代码中的console.log(stain)显示有一个空数组。 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 Sequelize官方文档参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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