πŸ‘€ Our most exciting product launch yet πŸš€ Join us May 8th for Sanity Connect

GROQ query to reference an actor

By Kapehe & Lo Etheridge

GROQ query to reference an actor and their name

*[_type == "movie" && references('person_matt-damon')]{
  "castNames": castMembers[].person->name
}

This GROQ query comes from the beginner GROQ stream featuring Kapehe and Lauren. This was from Part 2 of the GROQ streams.

It filters your Content Lake to all the types that have "movie". It then continues filtering down to any "movie" that references "person_matt-damon".

We renamed the projection we wanted to "castNames". So now when we use it in our frontend or anywhere, we only have to call it by the new name we gave it. And that would pull out the content that lives in: castMembers[].person->name. The result would also have that naming on it.

We are accessing the array of castMembers, the person reference in that array, and then pulling out just the name with the dereferencing operator (->).

The result would be all the movies in the Content Lake that reference Matt Damon but also all the castMembers and their names. Matt Damon would be in all those lists.

We are following this doc in the stream. And we are using the prebuilt movie Studio that you can find when you run sanity init in your command line.

Contributors

Other schemas by authors