See how we built our intranet. Live + Q&A, June 30

Filter query results by reference property in array

3 repliesLast updated: Nov 29, 2025

Hi, I was wondering how I could filter query results by a property that is a reference? i.e. i have X amount of “downloads” and want to filter them by a given “tag”. “tags” is an array of references.
AI Update

To filter query results by a reference property (like filtering "downloads" by a given "tag" where tags is an array of references), you'll want to use filtering within array projections using the @ operator (parent scope operator).

Here's the pattern that works:

*[_type == 'downloads']{
  'tags': tags[(@->someProperty == someValue)]->
}[length(tags) > 0]

For your specific case, if you want to filter downloads that have at least one tag matching certain criteria:

*[_type == 'downloads']{
  'tags': tags[(@->_id == "specific-tag-id")]->
}[length(tags) > 0]

The key parts here:

You can also add multiple conditions:

*[_type == 'downloads']{
  'matchingTags': tags[(@->active == true && @->category == "featured")]->
}[length(matchingTags) > 0]

Important: This syntax requires API version v2021-03-25 or later. Make sure your query client is configured to use this version:

const client = sanityClient({
  // ... other config
  apiVersion: '2021-03-25'
})

This approach is much more efficient than fetching all documents and filtering client-side, as the filtering happens at the query level in the Content Lake.

Show original thread
3 replies

Was this answer helpful?

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Related contributions