Unlock seamless workflows and faster delivery with our latest releases- get the details

Trouble querying a field with array of references in Slack thread

6 replies
Last updated: Sep 1, 2020
I have a document like so:
{
  ...restFields,
  name: `Test 123`,
  variants: [{ sku: `test1`, ...restFields}]
}
I’m trying to query this field like so:

*[variants[].sku match "*test*"]
This is returning no results. From the docs this seems to be how I would query that, but it does not work. Any help?
Aug 31, 2020, 4:00 PM
Does removing the the first asterisks in the match string work?
Sep 1, 2020, 1:08 PM
Nope, even doing this is not working
*[variants[].sku == "test1"] 
Sep 1, 2020, 1:30 PM
Can you post a query URL so can test? DM me if you don't want it public.
Sep 1, 2020, 1:45 PM
do i have to run a deploy to see the query url or does it store it somewhere haha?
Sep 1, 2020, 1:47 PM
went ahead and deployed it, dming you
Sep 1, 2020, 1:49 PM
Resolved on DM. Turned out that
variants
is an array of references, so the correct query was
*[variants[]->.sku match "*test*"]
Sep 1, 2020, 2:58 PM

Sanity– build remarkable experiences at scale

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

Was this answer helpful?