API Filtering; make sure collection type relation includes all items in list of strings

System Information
  • Strapi Version: v4.19.1
  • Operating System: Windows
  • Database: Postgres
  • Node Version: v20.11.0
  • NPM Version: v10.2.4
  • Yarn Version: N/A

Hello!

So I have Products, and Products have a relationship with many Product Tags. I want the user to be able to filter by tags. The issue is, if I use $in to check if the product’s tags are in the user’s filter list, it will return the product even if only one tag is in the list of filters, and two other tag filters are not apart of the Product.

How can I use the API to filter to make sure that ALL of the items in this [“tag1”, “tag2”, “tag3”] array for example exist in the Product’s Product Tag relations, by Product Tag name?

Thanks and let me know if I can provide any more info. I couldn’t find anything on Google and I’m pretty stumped. If it’s not possible I guess I will have to select all and then filter with JavaScript? Which would make pagination harder and make users download more data than they need.

What I've got so far
  const { requestUrl, mergedOptions } = buildStrapiRequestUrl("/products", {
    filters: {
      category: {
        slug: {
          $eq: props.category.attributes.slug,
        },
      },
      ...(selectedTags
        ? {
            product_tags: {
              name: {
                $in: selectedTags,
              },
            },
          }
        : {}),
    },
    sort: "isBestSeller",
    pagination: {
      pageSize: 19,
      page: 1,
    },
  });

Solved:

        filters:
          {
            $and: [
              ...selectedTags.map((tag) => {
                return {
                  product_tags: {
                    name: {
                      $eq: tag,
                    },
                  },
                };
              }),
            ],
          }