Filtering in populated data

System Information
  • Strapi Version: 4.1.2
  • Operating System: Linux Arch
  • Database: Postgres
  • Node Version: >=12.x.x <=16.x.x
  • NPM Version: >=6.0.0
  • Yarn Version: >=1.22

I am looking for the way how to filter populated data
I have this query request

stringify(
    {
      populate: {
        credentials: {
          populate: 'carriers',
        },
      },
      filters: {
        credentials: {
          carriers: {
            carrierID: {
              $eq: 'DHL',
            },
          },
        },
      },
    },
    {
      encodeValuesOnly: true,
    },
  );

and I always get all of the carriers as filter not works with this approach

Check out this example for populating with filtering: Population for REST API - Strapi Developer Docs

1 Like

I have the same problem, I couldn’t solve filtering among list items that populated in the query. boop`s answer is not useful for that scenario.

@boop is right:
I’m leaving here a sample for anyone who getting this same problem. in my case I’m fetching a single post with a relation called likedBy, and only want the username from this relation.
then this is the working populate:

{
          ...query,
          populate: {
            likedBy: {
              fields: ["username"],
            },
          },
        }

Hope that helps someone.
here is the doc that helped me: https://docs.strapi.io/dev-docs/api/rest/interactive-query-builder