Join live – Get insights, tips, + Q&A from Sanity developers on our latest releases

Understanding the use of @-> in GROQ queries and its power for filtering arrays and references.

13 replies
Last updated: Apr 8, 2022
*[_type==“accounts” && accountNumber == “0xb215014176720eda5334df07f827c3f11ec0f1bd” ]{ name,
transactions[]->{
value
}
}
Apr 7, 2022, 6:27 PM
If transactions is a reference, and value is a number, you should be able to do

transactions[@->value > 100]->{ ... }
Apr 7, 2022, 6:37 PM
thanks worked 🙂
Apr 7, 2022, 6:47 PM
Looks like you got it handled szofon, but in the future this is a great resource as a quick guide/cheat sheet for GROQ queries as well that may be helpful. Also, thanks for jumping in to help out, Matt, you rock!
Apr 7, 2022, 8:04 PM
thanks worked 🙂
Apr 7, 2022, 6:47 PM
If transactions is a reference, and value is a number, you should be able to do

transactions[@->value > 100]->{ ... }
Apr 7, 2022, 6:37 PM
user Y
i had walk through the docs many times prior, also the cheatsheet. But it was not clear what the @ really does, and how and where it could be used at the syntax flow, and for this specific use case @-> for filtering referenced document list, i find nothing. Is there some examples for this somewhere?
Apr 8, 2022, 5:36 AM
I’ve not seen examples like this before either. I actually learned about it from this slack group --unfortunately the message is gone now and I can’t recall who taught it to me
Apr 8, 2022, 6:45 PM
In a nutshell,
@
will return
this
while
@->
will expand/dereference
this
(its use implies that
this
is a reference).
Apr 8, 2022, 7:41 PM
user A
I think the concept that eluded me was that you can populate an array of references like that and then filter on a property of the array
Apr 8, 2022, 9:07 PM
I didn't grasp what the @ did because in most examples it's referring to the current context, but it wasn't obvious how powerful it is for arrays and references
Apr 8, 2022, 9:08 PM
Appreciate that feedback, Matt. There are certainly plenty of :mindblown: GROQ queries out there. It’s on my to-do list to better capture and consolidate them.
Apr 8, 2022, 9:53 PM
Appreciate that feedback, Matt. There are certainly plenty of :mindblown: GROQ queries out there. It’s on my to-do list to better capture and consolidate them.
Apr 8, 2022, 9:53 PM
It’s awesome what can be done with it. I’d love to use it with databases too as an alternative to GraphQL (which I’ve always struggled to grasp)
Apr 8, 2022, 10:30 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?