đź”® Sanity Create is here. Writing is reinvented. Try now, no developer setup

How to write a GROQ Query to Filter a Reference Field within Documents

2 replies
Last updated: Apr 16, 2021
Hello, I have two documents: "manga", "chapter"."chapter" has a reference field where you can choose only one manga. so when you add a new chapter you simply refer it to any manga you want.

I'm trying to get chapters with manga's _id and I'm struggling. how to write GROQ query with this kind of filter?
Apr 15, 2021, 8:25 PM
You should be able to query in reverse using the GROQ references function:

*[_type == 'manga'] {
  'chapter': *[_type == 'chapter' && references(^._id)]
If you’re after something different, please let me know.
Apr 15, 2021, 9:04 PM
Apr 16, 2021, 10:41 AM

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?