postgresql - Feathers-Sequelize with Postgres:如何查询数组
问题描述
我想看看一个数组中是否包含一个或多个值。
这是一个模型字段定义:
keywords: {
type: Sequelize.ARRAY(Sequelize.STRING),
defaultValue: [],
allowNull: false,
},
这是我正在测试的查询:
context.app.services.jobOffers.Model.findAll({
where: {
keywords: {
$contains: ['hello'],
},
},
})
.then(result => {
console.log('RESULT:', result)
})
.catch(err => {
console.log('ERROR:', err)
})
这是我收到的错误:
ERROR: TypeError: values.map is not a function
这是对类似问题的引用,我试图复制解决方案但没有效果。
https://github.com/feathersjs-ecosystem/feathers-sequelize/issues/135
解决方案
似乎问题出在 Sequelize 版本上。Feathers.js 的一位作者@daffl 向我阐明了这一点
“在 Sequelize v5 及更高版本中,您需要使用符号,如[Op.contains]
参见 ( http://docs.sequelizejs.com/manual/querying.html#operators )”
所以解决方法是更改这行代码
where: {
keywords: {
[Op.contains]: ['hello'],
},
},
推荐阅读
- sql - 从 R 查询 SQL 时如何用 0 替换 NA?
- angular - 在 Angular 7 中的每个列表项中集成下拉菜单并获得价值
- java - 如果不是 URL,请在线搜索 EditText 输入
- database - 新数据库和数据库内的新度量有什么区别?
- c# - 从同步方法调用异步任务而不需要任何返回(结果)
- c++ - 在 C++ 中,我遇到了一个我无法理解的编译器错误
- c++ - launch.json 无法调试 cpp 文件
- postgresql - PostGIS 3:没有为“st_equals”找到空间运算符:opfamily 36658 类型 36545
- swift - NSWorkspace.OpenConfiguration 忽略参数,尽管没有被沙盒化
- asp.net-mvc - 身份服务器 4 后注销 URL 空