Filter Views using userAttributes with arrays

I’m having issues creating a Filter View trying to filter on targeting values using the userAttributes object when dealing with array attributes.

So i have a custom plugin that lets the user do targeting against multiple string values.
This is AFAIK stored as a string array in Builder.
An example targeting on a page could be an audienceGroup with a value of ["20", "30"].

The actual targeting seems to work fine when i fetch Builder content providing the audienceGroup inside the userAttributes object (somehow Builder does an $or automatically since i can provide both ["20"] and ["30"] separately and match the correct content, but this is besides the point).

Now when i want to create a Filter View the matching of array values does not work.
Neither when i provide ["20", "30"] or the values separately it wont show any results.

So i try to use the Custom Query for Filter Views and write something like the following

{
    "data.userAttributes.audienceGroup": {
        "$eq": ["20", "30"]
    }
}

But it returns no matches.
I also tried using the $in operator instead and i also tried providing the values separately, as well as different ways of structuring the query, but it doesn’t seem to work.

Do you have any examples of using arrays of values in targeting and then Filtering based on those targeting values?

Hello @panen,

To properly filter these array values, you should use the $elemMatch operator within your custom query. This operator helps you match documents that contain elements that match all specified conditions.

{
  "data.userAttributes.audienceGroup": {
    "$elemMatch": {
      "$in": ["20", "30"]
    }
  }
}

This custom query should filter your content entries correctly based on the provided targeting values in the audienceGroup array. If you have any further questions or need additional assistance, feel free to ask!

Thanks,