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 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.

Was this answer helpful?