繁体   English   中英

过滤环回中字段的数组类型

[英]Filter for array type of field in loopback

我正在使用带有 mongodb 数据库的环回 v3 并为字段的数组类型实现过滤器。 inq 操作员不工作。

我有一个像下面这样的对象数组

[ 
  {
    "name":"name1",
    "title": "title1",
    "category": ["a", "b","c"]
  },

  {
    "name":"name2",
    "title": "title2",
    "category": ["x", "y","z"]
  },

  {
    "name":"name3",
    "title": "title3",
    "category": ["b", "d","e"]
  }

]

现在我想要一个列表,其中包含“b”的类别

所以我使用下面的过滤方法

filter: {where:{category:{inq:["b"]}}}

我认为inq不适用于这种情况。它给出了空响应。

输出:[]

我怎样才能得到我想要的输出。

期望的输出:

[ 
  {
    "name":"name1",
    "title": "title1",
    "category": ["a", "b","c"]
  },

  {
    "name":"name3",
    "title": "title3",
    "category": ["b", "d","e"]
  }

]

下面是我的属性

"properties": {
    "name": {
      "type": "string"
    },
    "title": {
      "type": "string"
    },
    "category": {
      "type": [
        "string"
      ]
    }
  },

请建议。

谢谢

对我来说,上面的场景工作正常。 尽管在您的代码中,数组右括号应该是]而不是} ,只是指出我在您的代码中发现的一些内容。

你是如何为此设置模型的?

"properties": {
    "name": {
      "type": "string"
    },
    "title": {
      "type": "string"
    },
    "category": {
      "type": [
        "string"
      ]
    }
  },

你的模型属性看起来像这样吗?

"role": {
  "type": "array",
  "default": [
    "patient"
  ]
}

让过滤器 = {role:{in:['doctor']}}

    this.find({
        where: filter
    }, cb);

暂无
暂无

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

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