我有一个类似于下面的博客文章列表
[
{
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
标签的帖子? - 所有匹配标签
foo
和bar
的帖子? - 所有没有标签的帖子?
最佳答案
您可以使用标准的/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/