How to Filter on Object Keys in a Nested Object in Groq-Req?

7 replies
Last updated: Mar 31, 2021
I want to filter on object keys in a nested object in the groq-req, how would I go about doing this? I want to only get one language from est_volume by providing a parameter
Mar 31, 2021, 4:19 PM
You can define the dat you want in the response so I guess you could just specify the language like “en” telling the db to only send you that key…
Mar 31, 2021, 4:28 PM
Do you know how to define the query? im stuck, can't find what syntax to use. It currently looks like this:
*[_type == "second_hand"]{
    title,
    carousel_list[]-> {
      carousel_image,
      carousel_item_name,
     	est_volume,
      price,
    }
  }
Mar 31, 2021, 4:30 PM
Ooh I figured it out! Thanks!
Mar 31, 2021, 4:32 PM
*[_type == "second_hand"]{
    title,
    carousel_list[]-> {
      carousel_image,
      carousel_item_name,
      est_volume,
      price,
      est_volume {
         en
      }
    }
  }

Mar 31, 2021, 4:32 PM
summin like this?
Mar 31, 2021, 4:33 PM
Yes, that was it. i got it working like this:
*[_type == "second_hand"]{
    title,
    carousel_list[]-> {
      carousel_image,
      carousel_item_name,
     	est_volume {
      "est_vol": $lang,
    },
      price,
    }
  }
Thanks for help
Mar 31, 2021, 4:33 PM
Great 🙂
Mar 31, 2021, 4:35 PM

Sanity.io – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Categorized in