GROQ query to find all movie screenings with a specific actor
Find new connections in a dataset by filtering a second time on dereferenced data
screeningsByActor.js
*[_type == 'screening']{
title,
movie->
}[$actorId in movie.castMembers[].person._ref]This GROQ snippet takes an $actorId and returns screening documents that have a reference to a movie with this actor. This is using the default movie schema and data that you can get by running sanity init in the Sanity CLI.
The query itself comes in three parts:
*[_type == 'screening']: Find all documents with a type ofscreening- Run a projection (
{}) to get the screening title (and any other information), and dereference themovieinformation:movie-> [$actorId in movie.castMembers[].person._ref]: Run a filter on the returned array to check if the actor's document ID is in the castMember array
This is an example of using GROQ for equijoins.
Contributor

Bryan Robinson
Sr. DevRel @ Algolia
United States