gpt4 book ai didi

loopbackjs - 如何找到与标签列表匹配的文档?

转载 作者:行者123 更新时间:2023-12-02 03:30:21 28 4
gpt4 key购买 nike

我有一个类似于下面的博客文章列表

[
{
title: "Post #1",
tags: ["foo", "bar"]
},
{
title: "Post #2",
tags: ["bar", "baz"]
},
{
title: "Post #3",
tags: []
},
{
title: "Post #4"
},
{
title: "Post #5",
tags: ["qux"]
},
...
]

如何使用标准的 /posts GET 方法来查找:

  • 所有匹配 foo 标签的帖子?
  • 所有匹配标签 foobar 的帖子?
  • 所有没有标签的帖子?

最佳答案

您可以使用标准的/posts GET 方法来查找:

  • 所有匹配 foo 标签的帖子?

    /posts?filter={"where": {"tags": {"inq": ["foo"]}}}

  • 所有匹配标签 foo 和 bar 的帖子?

    /posts?filter={"where": {"and": [{"tags": {"inq": ["foo"]}},{"tags": {"inq": ["bar "]}}]}}

  • 所有没有标签的帖子?

    /posts?filter={"where": {"tags": []}}

与数据库查询相比,Loopback 构建在 Express 之上并支持大多数查询,因为它在内部使用 native 数据库驱动程序来构建查询。

关于loopbackjs - 如何找到与标签列表匹配的文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27251887/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com