postgresql - Sails.js 在数组中搜索

标签 postgresql data-structures model sails.js waterline

我正在使用 sails ,我需要在数组中找到具有特定值的对象。

我有这个模型:

User = {
 data = { type: 'array}
}

当我这样做时:

User.find({data:3}).exec(...) 

// => It's returns nothing

如果我尝试这样做

User.find({data:{contains:3}}).exec(...)

// => It's will return all User who have '3' in the array 
but it will return the users whose have 34 or 13, ... too.

sails 中没有从数组中查找记录的解决方案吗?

如果我将数据类型设置为“json”会怎样?

谢谢!

最佳答案

实际上在 arrayjson 类型中搜索是不可能的。

你必须与协会联系起来:http://sailsjs.org/documentation/concepts/models-and-orm/associations

或者获取所有用户并手动进行搜索,但如果您的数据库中有很多用户,则不会优化

关于postgresql - Sails.js 在数组中搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33128500/

相关文章:

postgresql - 获取所有程序的、用户定义的函数

java - 表格数据的数据结构

performance - 从 AVL 树中获取中位数?

database - 我如何将数据库表与 ATK 中的模型相关联?

django - TypeError:“ModelBase”对象不支持索引。

c# - ORMLite/服务栈 : Joining Multiple Nested Tables Together

arrays - postgresql 将文本搜索到文本数组中

python - 关节点算法-后边缘识别

重命名表时,带有 --noinput 的 Django 南迁移不会删除内容类型

postgresql - 在 Debezium 中过滤读取访问事件