Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Sanity groq Filter by item in an array

By Surjith S M

This snippet will return only matched item in a sub array inside a document

return only matched variant


// Returns variant name matched in variant[] array

*[_type == "products" && slug.current == $slug][0] {
    variant[type match $variant][0]{
        ...
      }
  }
  
  
  
// Params

{
   "slug": "slug",
   "variant": "variant"
}

This query will help you to filter a document based on an item match inside an array inside the document.

Contributor

Other schemas by author