我正在使用 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”会怎样?
谢谢!
最佳答案
实际上在 array
或 json
类型中搜索是不可能的。
你必须与协会联系起来:http://sailsjs.org/documentation/concepts/models-and-orm/associations
或者获取所有用户并手动进行搜索,但如果您的数据库中有很多用户,则不会优化
关于postgresql - Sails.js 在数组中搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33128500/