node.js - 如何根据 Loopback 中的标签数组过滤订阅者

标签 node.js postgresql loopbackjs loopback

我有两个模型 - subscriberstags

示例数据:

{
 subscribers: [
  {
   name: "User 1",
   tags: ["a","b"] 
  },
  {
   name: "User 2",
   tags: ["c","d"] 
  }
 ]
}

我想根据标签过滤订阅者。

  • 如果我给 ab 标签,用户 1 应该列出
  • 如果我给 ac 标签, 用户 1 和用户 2 都应该列出

这是我尝试过的:

方法一:

tagssubscribers 模型中的一列,数据类型为数组

/subscribers/?filter={"where":{"tags":{"inq":["a","b"]}}} // doesn't work

方法二:

创建了一个单独的表 tags 并设置 subscribers 有很多 tags

/subscribers/?filter={"where":{"tags":{"inq":["a","b"]}}} // doesn't work

如何在不编写自定义方法的情况下在 Loopback 中实现这一点?

我将 Postgresql 作为连接器

最佳答案

更新

loopback docs 中所述你应该使用 inq 而不是 In

The inq operator checks whether the value of the specified property matches any of the values provided in an array. The general syntax is: {where: { property: { inq: [val1, val2, ...]}}}

来自这里:

/subscribers/?filter={"where":{"tags":{"In":["a","b"]}}}

对此:

/subscribers/?filter={"where":{"tags":{"inq":["a","b"]}}}

关于node.js - 如何根据 Loopback 中的标签数组过滤订阅者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52640158/

相关文章:

node.js - 在 openshift 上部署时的 Mongodb 和 Loopback

javascript - 如何处理 NestJS 中的 TypeORM 错误?

node.js - 通过对象中已有的数据进行查询

postgresql - 使用嵌套不在提高 PostgreSQL 中的查询性能

postgresql - 带有 Kubernetes 和 persistentDisk 的 Postgres

node.js - 环回 hasandbelongstomany 关系表不存在

javascript - Jasmine 和 node.js

javascript - Node JSON 输出格式错误,无法设置 HTTP header : Content-Length to fix

postgresql - 使用 jOOQ 获取表列表

node.js - 环回到多个静态文件的子域路由( Angular 应用程序)