How do I find documents that match a tag list?

I have a list of blog posts similar to below

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

      

How can I use the standard /posts

GET method for searching:

  • all posts matching the tag foo

    ?
  • all messages matching the foo

    AND tags bar

    ?
  • all posts that have no tags
+3


source to share


1 answer


You can use the standard GTS method for publishing:

  • all messages that match the foo tag?

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

  • all posts that match foo AND bar tags?

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

  • all posts that have no tags?

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



Compared to db queries, Loopback is built on top of Express and supports most queries as it uses its own database drivers to create queries.

+1


source







All Articles